fix(glob): strip trailing slash from gitignore-derived ignore patterns#1288
Merged
Simon (simonhj) merged 1 commit intov1.xfrom May 1, 2026
Merged
fix(glob): strip trailing slash from gitignore-derived ignore patterns#1288Simon (simonhj) merged 1 commit intov1.xfrom
Simon (simonhj) merged 1 commit intov1.xfrom
Conversation
fast-glob silently discards `ignore` entries that end in `/` — it treats them as literal directory paths rather than glob patterns. The standard gitignore convention of writing directory entries as `dist/` arrives here as `**/dist/` after `ignorePatternToMinimatch`, which fast-glob then drops, defeating the entire ignore. fast-glob walks the directory anyway and the result has to be filtered out post-walk — wasting a readdir of the entire subtree on every call. Strip the trailing slash before passing to fast-glob so the pattern actually matches.
Martin Torp (mtorp)
approved these changes
Apr 30, 2026
Contributor
Martin Torp (mtorp)
left a comment
There was a problem hiding this comment.
LGTM ✅ Thanks Simon (@simonhj)!
Contributor
|
Thank you Simon (@simonhj). I'll update this in the |
John-David Dalton (jdalton)
approved these changes
Apr 30, 2026
Contributor
|
Related to mrmlnc/fast-glob#437 |
John-David Dalton (jdalton)
added a commit
to SocketDev/socket-lib
that referenced
this pull request
Apr 30, 2026
- Replace `new Array()` with `new ArrayCtor()` and `pattern.charCodeAt` with `StringPrototypeCharCodeAt` so the helper is hijack-resistant (prim audit was flagging both). - Add 4 edge-case unit tests: mixed trailing/non-trailing patterns in same array, empty `ignore: []`, single-character `/` boundary (must not be stripped), no `ignore` option at all. - Inline the upstream fast-glob URLs in the header comment (mrmlnc/fast-glob#437, SocketDev/socket-cli#1288) so a future reader can jump straight to the bug-hunt context without grepping.
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
TL;DR Buggy glob pattern generation caused traversal of ignored trees.
ignoreentries that end in/— the underlying micromatch matcher treats a trailing slash as a literal character that requires a matching trailing slash on the input path, andreaddirentries never carry one. Validated this (to me non-obvious) behavior locally:dist/arrives at fast-glob as**/dist/afterignorePatternToMinimatch, so fast-glob walks the directory anyway and the result has to be filtered out post-walk — wasting areaddirof the entire subtree on every call.ignoreso the pattern actually matches.Test plan
globWithGitIgnoretests still pass (11 total: 10 existing + 1 new).pnpm check:tscclean.socket fixagainst a fixture with a 300 000-file gitignoreddist/and--max-old-space-size=128no longer OOMs and proceeds past the glob walk in well under a second.Note
Medium Risk
Changes globbing ignore behavior for gitignore-derived directory entries, which can alter which files are scanned/returned. Low implementation complexity, but impacts filesystem traversal and results in tooling that relies on
globWithGitIgnore.Overview
Fixes
globWithGitIgnoreso gitignore directory patterns written with a trailing slash (e.g.dist/) actually preventfast-globfrom walking those directories by normalizing ignore patterns via a newstripTrailingSlashhelper.Adds a regression test confirming that
dist/in.gitignoreexcludes files underdist/from glob results.Reviewed by Cursor Bugbot for commit ee42879. Configure here.