biome nursery/useUnicodeRegex: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 2×
When the RegExp constructor is called with a non-string pattern (e.g., another RegExp), adding 'u' as a second argument is ignored per spec, but if the first argument is a RegExp and flags are provide
Program
Output
i
iu
- fired
- 2 before · 0 after
- runs
- each version twice, same file name, no network
Judge Nemotron 3 Ultra advisory intended-change · low
The rule adds the 'u' flag to regexes lacking Unicode mode. The program constructs a new RegExp from an existing one and passes an additional 'i' flag; per the spec, the new RegExp inherits the source regex's flags unless overridden, so adding 'u' to the source makes the copy's flags become 'iu' instead of 'i'. This is the documented semantic change the rule exists to make.
Explanation Nemotron 3 Super unverified
The original regex `/a/g` has only the global flag; adding `u` via the fix changes its behavior to Unicode mode, which alters how patterns like `\w` or case-insensitive matching are interpreted—even if unused here. The copy inherits both `i` and `u` flags, so its `.flags` becomes `iu` instead of `i`. Though the current pattern `/a/` is unaffected by Unicode mode, the fix assumes safety without verifying that added flags don’t alter semantics for potential future patterns, making it unsafe in general. The observed change in output confirms the behavioral shift.
Reproduce
- file
prog.js(the before program)- minimized program
- r1-p003.js
- evidence sheet
- r1-p003.md
- regression fixture
- r1-p003.js the minimized program with a header stating the observed change, for the tool's test suite
node prog.js bunx @biomejs/biome lint --only=nursery/useUnicodeRegex --write prog.js node prog.js
Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra
useUnicodeRegex fix · nursery useUnicodeRegex regex constructor flags · RegExp constructor unicode flag propagation · useUnicodeRegex rule RegExp flags behavior
- related biomejs/biome/issues/11933 same rule but different construct (invalid patterns in unicode mode vs RegExp constructor flag handling)
- related biomejs/biome/issues/5693 same domain (regex autofix) but different construct (useRegexLiterals escaping vs useUnicodeRegex flag handling)
Details
- program
- RegExp constructor with RegExp arg
- hazard
- When the RegExp constructor is called with a non-string pattern (e.g., another RegExp), adding 'u' as a second argument is ignored per spec, but if the first argument is a RegExp and flags are provide
- oracle
stdout before: i stdout after: iu- run
- 2026-10-17T20-50-43-467Z-vlrv-biome-nursery_useUnicodeRegex
generated program (3 lines) and the fix's diff
--- orig.js 2026-10-17 16:50:56.840217652 -0400 +++ fixed.js 2026-10-17 16:50:57.122222940 -0400 @@ -1,3 +1,3 @@ -let base = /a/g; -let copy = new RegExp(base, 'i'); +let base = /a/gu; +let copy = new RegExp(base, 'iu'); console.log(copy.flags);
rule documentation given to the models
Summary
- Name: useUnicodeRegex
- Fix: safe
- Default severity: info
- Available from version: 2.4.5
- Diagnostic category: lint/nursery/useUnicodeRegex
Description
Enforce the use of the `u` or `v` flag for regular expressions.
The `u` flag (Unicode mode) and `v` flag (Unicode Sets mode) enable proper handling
of Unicode characters in regular expressions. Without these flags, regex patterns
may not correctly match Unicode characters like emoji or characters outside the
Basic Multilingual Plane.
The `u` flag was introduced in ES2015 and enables:
- Correct handling of surrogate pairs (e.g., emoji)
- Unicode code point escapes (`\u{...}`)
- Case-insensitive matching for Unicode characters
The `v` flag was introduced in ES2024 and provides all `u` flag features plus:
- Set notation in character classes
- String literals in character classes
- Improved Unicode property escapes
Examples
Invalid
```js,expect_diagnostic
/foo/;
```
```js,expect_diagnostic
/foo/gi;
```
```js,expect_diagnostic
new RegExp("foo");
```
```js,expect_diagnostic
new RegExp("foo", "gi");
```
Valid
```js
/foo/u;
/foo/v;
/foo/giu;
new RegExp("foo", "u");
new RegExp("foo", "giv");
new RegExp("foo", flags); // dynamic flags are ignored
```