Skip to content

fix(filter): tolerate a leading dot in --ext/--no-ext values - #365

Open
MsfPablo wants to merge 1 commit into
equationzhao:masterfrom
MsfPablo:fix/no-ext-leading-dot
Open

MsfPablo wants to merge 1 commit into
equationzhao:masterfrom
MsfPablo:fix/no-ext-leading-dot

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Sep 1, 2026

Copy link
Copy Markdown

What

--no-ext .txt (with a leading dot) failed to exclude a.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 / ..csv and matched nothing.

Fixes #335.

Repro

tmp=$(mktemp -d); touch "$tmp/a.txt" "$tmp/b.csv" "$tmp/noext"
g --no-config --disable-index --classic -A --byline --no-ext .txt "$tmp"

Before: a.txt b.csv noext (nothing excluded).
After: b.csv noext (a.txt excluded), matching the behavior of --no-ext txt.

Change

internal/filter/itemfliter.go — add extSuffix(ext) which trims a single leading dot before prepending the separator, and use it in both RemoveByExt (--no-ext) and ExtOnly (--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.goTestRemoveByExtAcceptsLeadingDot and TestExtOnlyAcceptsLeadingDot cover 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 vet and gofumpt --extra clean.

--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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] --no-ext with a leading dot fails to exclude matching files

1 participant