Correct escaping of regexp patterns created at run-time#2482
Merged
Conversation
This was referenced Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Corrects escaping of regexp patterns created at run-time via
new RegExp("\n"),RegExp("\n"),/x/.compile("\n"),"x".match("\n"), etc.Details
The
/character is not valid without escaping in regexp literals outside class sets (however, it's valid inside them). New line characters are not valid in regexp literals either. There are cases which aren't escaped correctly (e.g.new RegExp("[/]"),new RegExp("\r[\n]"), etc.) This PR aims to fix this.Also, .NET Regex objects can be exposed to the engine. However, it's incorrect to return the .NET pattern as if it were a JS regexp pattern. This could be misleading. The PR suggests a placeholder (which is an invalid pattern BTW) instead:
?[native regex]. This is a breaking change though. I don't insist on it if you don't think it's a good idea.Finally, makes a minor improvement to the Repl app: in interactive mode, it prints the regexp literal (like e.g. Chrome or Firefox dev tools do) instead of the meaningless
{}text.Linked issue
n/a
Test plan
Jint.Testsdotnet test --configuration ReleaselocallyJint.Tests.Test262and confirmed no regressionsJint.Tests/Runtime/InteropJint.BenchmarkBreaking change?
Yes. Minor behavioral breaking change to
JsRegExp.SourceandToStringfor native .NET Regex objects exposed to the engine, as explained above.