Skip to content

Find named groups with letters that are not ASCII in --js to close #816 - #833

Merged
mathiasrw merged 3 commits into
mainfrom
fix/816
Oct 23, 2026
Merged

mathiasrw merged 3 commits into
mainfrom
fix/816

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #816

Stacked on #832.

Change

The names of named groups were only found when they were ASCII ([A-Za-z_$][\w$]*). So with (?<año>\d) and rr_año in the code, RexReplace did not see that the code uses a group, ran it once per file where the groups are not there, and it failed with ReferenceError.

Now a name is found with the same rule as a name in javascript: \p{ID_Start} and \p{ID_Continue}.

> echo -n a1b2 | rexreplace '(?<日>\d)' 'rr_日 * 2' --js
a2b4

The panic for a name that ends with _ (#825) works for these names too.

Tests

test/fix/816.test.js is new, and fails without the fix. yarn test-ci passes.

From the review of 23 October.

After the review of 24 October

  • The names of the groups are read from the compiled regex, and not by scanning the pattern. So text that only looks like a group, like \(?<a_>b or [(?<a_>], is not one, and is no longer a panic (from the review of Access named groups from --js code to close #825 #832). It also works for any name javascript allows.
  • rr_year_ on its own is now seen as a use of the group. Before, rr_year_ + "|" gave ReferenceError: rr_year_ is not defined, an old bug from Give --js code the named groups to close #799 #806 on the same line.

Follow-up

test/fix/816.test.js also shows the code for the odd names: rr_año_ (the space cousin), rr_𝒜 (outside the BMP, the reason for the u flag), rr_$é, rr_Æble and rr_x٣, and that rr_rr_year is not the group year. 10 of 11 fail without the fix.

@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 13:17
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 13:19
@mathiasrw
mathiasrw added this pull request to stack #841 October 23, 2026 13:56
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 15:38
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 15:42
@mathiasrw
mathiasrw removed this pull request from stack #841 October 23, 2026 15:57
@mathiasrw
mathiasrw added this pull request to stack #849 October 23, 2026 16:12
@mathiasrw
mathiasrw removed this pull request from stack #849 October 23, 2026 16:12
@mathiasrw
mathiasrw added this pull request to stack #850 October 23, 2026 16:17
@mathiasrw
mathiasrw removed this pull request from stack #850 October 23, 2026 16:47
@mathiasrw
mathiasrw added this pull request to stack #853 October 23, 2026 16:51
Base automatically changed from fix/825 to main October 23, 2026 16:58
@mathiasrw
mathiasrw merged commit a8cb407 into main Oct 23, 2026
7 checks passed
@mathiasrw
mathiasrw deleted the fix/816 branch October 23, 2026 17:12
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.

Fix named groups with letters that are not ASCII in --js

1 participant