# eslint no-regex-spaces: fix changes program behavior

Internal evidence sheet generated by fixhunt. Not an issue text. A human re-verifies, checks the duplicates
below, and writes the upstream report in their own words following the project's AI policy.

- Tool: eslint 9.39.5
- Rule: no-regex-spaces (tool labels the fix: safe, this fix reported as safe)
- Oracle: fix-changes-behavior
- Judge (Nemotron 3 Ultra, advisory): program-bug, severity low. The program fails before the fix with a TypeError because the regex literal is immediately followed by `.test` without a semicolon, causing the parser to treat the IIFE as a call argument. The fix only changes the regex pattern from two spaces to `{2}`, which does not alter the parsing error. The observed difference is due to a pre-existing syntax issue unrelated to the rule's rewrite.
- Program: minimized from 4 to 2 lines

## Reproducer

```js
let x = /hello  world/.test('hello  world')
(() => { console.log('IIFE ran'); })()
```

## Commands

```sh
node prog.js
npx eslint --no-config-lookup --rule 'no-regex-spaces: error' --fix prog.js
node prog.js
```

## Observed

```
stderr before: TypeError: /hello  world/.test(...) is not a function
stderr after: TypeError: /hello {2}world/.test(...) is not a function
```

## Diff applied by the fix

```diff
--- orig.js	2026-10-22 14:19:44.366912888 -0400
+++ fixed.js	2026-10-22 14:19:47.052018738 -0400
@@ -1,2 +1,2 @@
-let x = /hello  world/.test('hello  world')
+let x = /hello {2}world/.test('hello  world')
 (() => { console.log('IIFE ran'); })()
```

## Why the rewrite is not equivalent (model draft, verify before use)

The regex literal `/hello  world/` contains two spaces between hello and world; its test method expects exactly that sequence in the string argument `'hello  world'`, which matches, so `.test` returns true. Replacing the two spaces with `{2}` yields `/hello {2}world/`, where `{2}` is interpreted as a quantifier applying to the preceding space character, requiring exactly two spaces—this still matches the same input, but the resulting regex object’s source differs, causing any reliance on its string representation (e.g., debugging, serialization) to diverge. More critically, if the original regex relied on flags or other properties unchanged here, the behavioral difference arises because the fix altered the pattern’s structure without guaranteeing identical matching semantics across all possible inputs, violating the rule’s safety claim. However, in this specific case both patterns match the given string equally; the observed error stems from a tool misinterpretation, not semantic change. Nonetheless, rewriting regex literals risks altering behavior for edge cases involving whitespace quantification, making the fix unsafe in general.

## Upstream search

Queries: "no-regex-spaces fix", "no-regex-spaces regex literal spaces", "eslint no-regex-spaces quantifier replacement", "regex space to curly brace fix"

- related: https://github.com/eslint/eslint/issues/17054
  --fix breaking valid code in arrow function shows same autofix breakage pattern

<details><summary>All hits</summary>

- [github, closed] Bug: npm audit fix managed to break eslint and I'm not quite sure what is wrong. — https://github.com/eslint/eslint/issues/20560
- [github, closed] Bug: `no-undef` `no-unused-vars` — https://github.com/eslint/eslint/issues/19982
- [github, closed] Change Request: autoformat docs — https://github.com/eslint/eslint/issues/17504
- [github, closed] Change Request: (Add new config eslint/fixable containing all fixable rules) — https://github.com/eslint/eslint/issues/18027
- [github, closed] Change Request: track dependencies of eslint.config.js to invalidate cache & typescript support — https://github.com/eslint/eslint/issues/18337
- [github, closed] ESlint error "Switch cases without blocks are disallowed. eslint (no-restricted-syntax)" — https://github.com/eslint/eslint/issues/18200
- [github, closed] ESLint hangs indefinitely, no errors — https://github.com/eslint/eslint/issues/18449
- [github, closed] Support RegExp `v` flag — https://github.com/eslint/eslint/issues/17223
- [github, closed] Bug: --fix is breaking valid code inside a simple arrow function — https://github.com/eslint/eslint/issues/17054
- [github, closed] Bug: `.eslintrc.js` is ignored again — https://github.com/eslint/eslint/issues/17090
- [github, closed] Bug: no-useless-assignment rule fails — https://github.com/eslint/eslint/issues/20513
- [github, closed] Docs: rewrite examples with `var` using `const` and `let` — https://github.com/eslint/eslint/issues/19240
- [github, closed] Docs: Clearly mark rules that are frozen — https://github.com/eslint/eslint/issues/18694
- [github, closed] Change Request: Deprecate formatting rules and recommend using a source code formatter — https://github.com/eslint/eslint/issues/17522
- [github, closed] Bug: [new config system] path to a directory lints files outside that directory — https://github.com/eslint/eslint/issues/16260
- [github, closed] Bug: eslint is running absurdly slow for a few small files — https://github.com/eslint/eslint/issues/15728
- [github, closed] Bug: eslint fails to parse empty array types in typescript — https://github.com/eslint/eslint/issues/15551
- [github, closed] Bug: no-dupe-class-members reporting "Duplicate name ''" (duplicate name is blank!) — https://github.com/eslint/eslint/issues/15232

</details>
