Repository navigation
fix(js_analyze): don't apply noAdjacentSpacesInRegex fix inside character classes - #11563
Conversation
…cter classes (biomejs#11419) run() scanned the regex source as raw bytes with no notion of being inside a `[...]` character class, so `{n}` — which is meaningless there and matches three extra literal characters instead of quantifying — was substituted for runs of spaces inside classes too. Track class depth (ignoring escaped brackets) while scanning, and skip space runs found while inside a class: `{n}` isn't a quantifier there, so there's nothing sound to rewrite them into. A run outside a class is still detected and fixed as before, including in a literal that also contains an untouched run inside a class.
|
A maintainer will take a look as soon as they can. In the meantime, please make sure that:
|
🦋 Changeset detectedLatest commit: 5338079 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Caution Review failedAn error occurred during the review process. Please try again later. Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
Fixes #11419.
noAdjacentSpacesInRegex'srun()scans the regex source as raw bytes with no notion of being inside a[...]character class. Runs of adjacent spaces found there get rewritten into a{n}quantifier just like anywhere else in the pattern — but{n}isn't a quantifier inside a character class, it's three more literal members of the set. The safe fix silently changes what the regex matches:Credit to @Lstarsky0's analysis in the issue, which traced this precisely to the byte-level scan having no class or escape awareness.
Fix
Track character-class depth while scanning (toggling on unescaped
[/]), and skip space runs found whilein_class. A run outside a class in the same literal is still detected and fixed as before — the fix doesn't bail out of the whole literal, only the in-class portion is left untouched.Test plan
valid.jsonc: spaces fully inside a class no longer get a diagnostic (/[\s ]/g,/[ ]/,/[a-z ]/)invalid.jsonc:/[a-z ] b/) confirming the outer run is still merged into a quantifier while the class is left untouched/\[ \]/) confirming they're correctly treated as literal, not a class, so the run between them is still fixed as beforecargo test --test spec_testsinbiome_js_analyze: 2865 passed, 0 failed (full suite)This PR was written primarily by Claude Code (investigation, fix, and tests). I reviewed the change and test results before opening this PR.