Skip to content

don't expand directories on a terminal negation extglob#207

Open
hong4rc wants to merge 1 commit into
SuperchupuDev:mainfrom
hong4rc:fix/negation-extglob-expand
Open

don't expand directories on a terminal negation extglob#207
hong4rc wants to merge 1 commit into
SuperchupuDev:mainfrom
hong4rc:fix/negation-extglob-expand

Conversation

@hong4rc

@hong4rc hong4rc commented Jul 3, 2026

Copy link
Copy Markdown

Fixes #188. With the default expandDirectories: true, a pattern ending in a negation extglob returns the files it should exclude — glob(['loc/**/!(en.po)']) hands back every en.po.

The issue is labeled upstream, but picomatch is correct: picomatch('loc/**/!(en.po)')('loc/one/en.po') is false. The bug is in tinyglobby's own normalizePattern, which appends /** to any pattern not ending in * — so loc/**/!(en.po) becomes loc/**/!(en.po)/**, and now !(en.po) matches the directory while the trailing /** re-adds en.po underneath. Running the same glob with expandDirectories: false returns the correct result, confirming the append is the cause.

The fix skips the /** append when the final segment is a negation extglob. It's deliberately narrow — only a terminal !(...) — so loc/**/!(en).po and other forms still expand as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some extglob negation patterns are not working with expandDirectories: true

1 participant