fix(tags): don't panic on tag filters with empty operands#758
Open
nikolauspschuetz wants to merge 1 commit into
Open
fix(tags): don't panic on tag filters with empty operands#758nikolauspschuetz wants to merge 1 commit into
nikolauspschuetz wants to merge 1 commit into
Conversation
matchAnd trims and strips '@' from each operand and then indexes tag[0] without checking for an empty string. A user-supplied --tags filter with an empty operand — e.g. "@one,,@two", a trailing "@one,", a leading ",@one", or "@one&&" — produces an empty operand and panics with 'index out of range [0] with length 0' instead of filtering. Guard the empty operand before indexing: an empty tag can never be present on a pickle, so it fails the AND (matching the existing else branch) and is harmlessly ignored for OR. Adds regression cases covering the malformed filters that previously panicked. Signed-off-by: Nikolaus Schuetz <nikolauspschuetz@gmail.com>
Author
|
One design note worth your call: this fix makes an empty operand forgiving — |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ApplyTagFilterpanics on a--tagsfilter that contains an empty operand.matchAndtrims each operand and strips@, then immediately indexestag[0]:Any filter that splits to an empty operand triggers
runtime error: index out of range [0] with length 0:@one,,@two(double comma)@one,(trailing comma),@one(leading comma)@one&&(trailing&&)@one&&&&@two(double&&)Since the filter string comes straight from user input (
-t/--tags), a small typo crashes the whole run with a stack trace instead of a graceful result.Fix
Guard the empty operand before indexing. An empty tag can never be present on a pickle, so it fails the
AND— identical to what the existingelsebranch (contains(tags, "")→false) would compute if it were reachable — and is harmlessly ignored for theOR(comma) case:Tests
Added regression cases to
Test_ApplyTagFilterfor all five malformed filters above (each previously panicked; behaviour:@one,,@two→{p1, p2},@one,→{p1},,@one→{p1},@one&&→{},@one&&&&@two→{}).Verified:
main(index out of range [0] with length 0).go test ./internal/tags/— passes with the new cases.go vet+gofmtclean.