Skip to content

fix(research): compile globs character by character so regex metacharacters stay literal - #179

Merged
adityankale190895 merged 3 commits into
DiffCI:mainfrom
FredApps:fix/research-glob-matcher
Nov 18, 2026
Merged

adityankale190895 merged 3 commits into
DiffCI:mainfrom
FredApps:fix/research-glob-matcher

Conversation

@FredApps

Copy link
Copy Markdown
Contributor

Fixes #178

What changed

regexFrom in src/research/baseline/matcher.ts built its RegExp by escaping only \ and . and then rewriting *. It now compiles the glob one character at a time:

Glob Before After
(, ), |, ^, $, + regex operators (+ threw) literal
? regex quantifier one character, not /
** not next to / (**, **.js) same as * crosses directories
\x literal backslash, then x literal x
[a-z], [!a-z] regex class (no !) glob class; an unclosed [ is literal
**/, trailing /**, *, {a,b} unchanged unchanged

Regression tests

tests/research/baseline/matcher.test.ts adds four example tests: literal metacharacters (app/(shop)/**, c++/*), ?, classes and escapes (app/\[id\]/*), and ** away from a slash. It also adds a fast-check property that matchesAny never throws for any path and pattern. All four example tests fail on main. The three existing tests and tests/planner/path-baseline.test.ts still pass.

Validation

npm run typecheck, npm test and npm run audit:boundary pass.

Not covered

src/planner/planner.ts:13-46 has an identical copy of this matcher, which DefaultCIPlanner uses. That file is outside this change. It needs the same fix, or it could import this one.

…acters stay literal

regexFrom escaped only backslash and dot, so ( ) | ^ $ reached the
RegExp as operators, + threw, ? was a quantifier, and a ** not next to
a slash could not cross directories.

Fixes DiffCI#178

Signed-off-by: FredApps <[email protected]>
FredApps added a commit to FredApps/core that referenced this pull request Nov 17, 2026
Align regexFrom with the research matcher fix for DiffCI#178 (PR DiffCI#179): + is
literal, ? is one character within a segment, [...] and [!...] are
character classes, and a backslash escapes the next character. c++/** now
matches c++/ only instead of failing to compile.

Refs DiffCI#173, DiffCI#178

Signed-off-by: FredApps <[email protected]>
A reversed range such as [z-a] compiled to an invalid RegExp, so matchesAny
still threw for some patterns. Fall back to a literal [ when the class does
not compile, and cover it with example tests.

Signed-off-by: FredApps <[email protected]>
Read an invalid class like [z-a] the way the planner's matcher in DiffCI#174 does:
it cannot rule a change out, so the task runs instead of being skipped.

Signed-off-by: FredApps <[email protected]>

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross-review at c4530ec.

Checked:

  • The four example tests and the fast-check property fail without the change, and tests/planner/path-baseline.test.ts still passes.
  • The branch is up to date with main, and typecheck passes.

Fixed:

  • The "never throws" claim didn't hold. A class that RegExp rejects, such as [z-a] or [a-\], threw "Range out of order". fast-check rarely generates one, so the property passed anyway.
    • a3a090c read such a class as literal text.
    • c4530ec replaced that with the reading #174 gives the planner's copy: an invalid pattern counts as matching, so the task runs instead of being skipped.
    • Example assertions cover it.

CI is green on c4530ec.

Open: src/planner/planner.ts still has its own copy of this matcher. #174 rewrites it the same way, so the two should stay in step or share one module.

@FredApps
FredApps marked this pull request as ready for review November 18, 2026 00:56
@adityankale190895
adityankale190895 merged commit 7d98c08 into DiffCI:main Nov 18, 2026
13 checks passed
adityankale190895 pushed a commit that referenced this pull request Nov 18, 2026
* fix(planner): match task input patterns as path globs

A bare or mid-segment ** (GitHub's **.js example) now matches at any depth,
( ) $ ^ | are literal so app/(marketing)/** and routes/$slug.tsx match
themselves, and a pattern that cannot compile triggers its task instead of
throwing out of plan().

Fixes #173

Signed-off-by: FredApps <[email protected]>

* fix(planner): read task input globs the way the research matcher does

Align regexFrom with the research matcher fix for #178 (PR #179): + is
literal, ? is one character within a segment, [...] and [!...] are
character classes, and a backslash escapes the next character. c++/** now
matches c++/ only instead of failing to compile.

Refs #173, #178

Signed-off-by: FredApps <[email protected]>

---------

Signed-off-by: FredApps <[email protected]>
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.

Glob matcher passes regex metacharacters through: '+' throws, '(…)' and '?' mismatch, bare '**' misses nested paths

2 participants