Skip to content

fix(js_analyze): don't apply noAdjacentSpacesInRegex fix inside character classes - #11563

Merged
dyc3 merged 1 commit into
biomejs:mainfrom
santichausis:fix/no-adjacent-spaces-in-regex-character-class
Oct 1, 2026
Merged

dyc3 merged 1 commit into
biomejs:mainfrom
santichausis:fix/no-adjacent-spaces-in-regex-character-class

Conversation

@santichausis

@santichausis santichausis commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #11419.

noAdjacentSpacesInRegex's run() 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:

/[\s   ]/   // -> /[\s {3}]/ — now also matches "1", "2", "{", "}"

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 while in_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

  • Added 3 cases to valid.jsonc: spaces fully inside a class no longer get a diagnostic (/[\s ]/g, /[ ]/, /[a-z ]/)
  • Added 2 cases to invalid.jsonc:
    • a mixed literal (/[a-z ] b/) confirming the outer run is still merged into a quantifier while the class is left untouched
    • escaped brackets (/\[ \]/) confirming they're correctly treated as literal, not a class, so the run between them is still fixed as before
  • cargo test --test spec_tests in biome_js_analyze: 2865 passed, 0 failed (full suite)
  • Added a changeset

This PR was written primarily by Claude Code (investigation, fix, and tests). I reviewed the change and test results before opening this PR.

…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.
@agentscanapp

agentscanapp Bot commented Aug 31, 2026

Copy link
Copy Markdown

A maintainer will take a look as soon as they can. In the meantime, please make sure that:

  • the description follows our PR template
  • any related issues are linked
  • existing tests still pass

@changeset-bot

changeset-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5338079

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

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

@github-actions github-actions Bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Aug 31, 2026
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.


Comment @coderabbitai help to get the list of available commands.

@codspeed

codspeed Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 73 untouched benchmarks
⏩ 233 skipped benchmarks1


Comparing santichausis:fix/no-adjacent-spaces-in-regex-character-class (5338079) with main (28b8e9c)

Open in CodSpeed

Footnotes

  1. 233 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@dyc3
dyc3 merged commit a4e6528 into biomejs:main Oct 1, 2026
36 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 noAdjacentSpacesInRegex safe fix corrupts character classes: [\s ] → [\s {3}]

2 participants