Conversation
--ext and --no-ext built the match suffix as "."+ext, so a user value
that already carried a leading dot (".txt") became "..txt" and matched
nothing. Strip one leading dot from the supplied extension so "txt" and
".txt" exclude/keep the same files.
Fixes equationzhao#335
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.
What
--no-ext .txt(with a leading dot) failed to excludea.txt, and--ext .csv(with a leading dot) likewise matched nothing. Both filters built the match suffix as"." + ext, so a user value that already carried a leading dot became..txt/..csvand matched nothing.Fixes #335.
Repro
Before:
a.txt b.csv noext(nothing excluded).After:
b.csv noext(a.txtexcluded), matching the behavior of--no-ext txt.Change
internal/filter/itemfliter.go— addextSuffix(ext)which trims a single leading dot before prepending the separator, and use it in bothRemoveByExt(--no-ext) andExtOnly(--ext). They share the root cause, so both are fixed together;"txt"and".txt"now exclude/keep the same files.Tests
internal/filter/itemfliter_test.go—TestRemoveByExtAcceptsLeadingDotandTestExtOnlyAcceptsLeadingDotcover both the bare and leading-dot forms. The leading-dot subtests fail on the pre-fix code (RemoveByExt(".txt") kept [a.txt b.csv noext],ExtOnly(".csv") kept []).go test ./internal/filter/...passes;go vetandgofumpt --extraclean.