You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
a fresh node startup has populated RegExp statics #43740
node, and then RegExp.$_, will print out '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'.
This also applies to $&.
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
No response
What do you see instead?
I expect the empty string for all RegExp statics.
This is a problem for a few reasons:
it exposes internal regular expression usage in node core
the value might change from any version to any version, so if anyone's foolish enough to rely on it, they'll break in a non-major
it's unseemly
If there's a point, right before node starts running user code, and right before the repl becomes available, then we could execute a trivial regular expression operation to clear all the statics.
Alternatively, this may be exposing non-primordial regex usage, and it's likely that switching to primordials (since I believe they'd update the statics on the primordial RegExp instead of the global RegExp) would solve this as well.
it's likely that switching to primordials (since I believe they'd update the statics on the primordial RegExp instead of the global RegExp) would solve this as well.
Before user code is executed, primordials.RegExp === globalThis.RegExp, so that wouldn't help. Creating an empty RegExp sounds fine though.
@hemanth if you want to work on the REPL side, that'd be great, I have a fix ready for the other problem.
Using SafeRegExp is not very practical because that would mean we can no longer use regex literals in core. Trying to migrate all of core to SafeRegExp seems like an unreasonable amount of work.
From my point of view #20549 (comment) and #20549 (comment) is a good TL;DR for this thread. I'd say let's try this approach and run benchmark to see how it performs. IMO it would be worth creating a SafeRegExp class in primordials rather than the getInternalGlobal hack.
I wonder if ShadowRealms integration gives a new solution to this problem, allowing us to run REPL code on another Realm sounds like something that should also fix the issue. Should we move this discussion to #18931 since only the REPL is at stake now?
Activity
ljharb commentedon Jul 8, 2022
cc @aduh95
hemanth commentedon Jul 8, 2022
I would like to work on the fix for this. Looks like it is a side of this.
ljharb commentedon Jul 8, 2022
ah, maybe the statics are populated by the same realm then :-/ that would be great for the repl, but wouldn't address node itself.
richardlau commentedon Jul 8, 2022
Duplicate of #18931?
ljharb commentedon Jul 8, 2022
The repl part, yes - but not the
node -pepart.aduh95 commentedon Jul 8, 2022
Before user code is executed,
primordials.RegExp === globalThis.RegExp, so that wouldn't help. Creating an empty RegExp sounds fine though.@hemanth if you want to work on the REPL side, that'd be great, I have a fix ready for the other problem.
hemanth commentedon Jul 8, 2022
@aduh95 Trying to understand the intent behind this.
regExMatcher.exec(savedRegExMatches.join(sep))results in:aduh95 commentedon Jul 8, 2022
My understanding is it's trying to clear up whatever RegEx node internals may have run between two REPL entries if that makes sense.
RegExpstatics.RegExpstatics in the same state their original operation should have left them.I think that works for
RegExp.$1toRegExp.$9, but not the other ones. Not sure this could be achieve without re-running the user code.hemanth commentedon Jul 8, 2022
If we use primordial
SafeRegExpwe can avoid this side effect?aduh95 commentedon Jul 8, 2022
Using
SafeRegExpis not very practical because that would mean we can no longer use regex literals in core. Trying to migrate all of core toSafeRegExpseems like an unreasonable amount of work.hemanth commentedon Jul 9, 2022
@aduh95 Hmm, We should revive #20549 ?
aduh95 commentedon Jul 9, 2022
From my point of view #20549 (comment) and #20549 (comment) is a good TL;DR for this thread. I'd say let's try this approach and run benchmark to see how it performs. IMO it would be worth creating a
SafeRegExpclass in primordials rather than thegetInternalGlobalhack.I wonder if ShadowRealms integration gives a new solution to this problem, allowing us to run REPL code on another Realm sounds like something that should also fix the issue. Should we move this discussion to #18931 since only the REPL is at stake now?
benjamingr commentedon Jul 9, 2022
Isn't
RegExp.$_a standard web-compatibility legacy feature? Spec wise are we safe to remove and not support it?aduh95 commentedon Jul 9, 2022
It's implemented by V8, I'm sure we can easily disable it – but yes, as far as ECMAScript is concerned, it doesn't exist.
6 remaining items
lib: reset `RegExp` statics before running user code
lib: reset `RegExp` statics before running user code
lib: reset `RegExp` statics before running user code
lib: reset `RegExp` statics before running user code
lib: reset `RegExp` statics before running user code
lib: reset `RegExp` statics before running user code
lib: reset `RegExp` statics before running user code
lib: reset `RegExp` statics before running user code
lib: reset `RegExp` statics before running user code
lib: reset `RegExp` statics before running user code
lib: reset `RegExp` statics before running user code