-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: reset RegExp
statics before running user code
#43741
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('node:assert'); | ||
const { spawnSync, spawn } = require('node:child_process'); | ||
aduh95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
assert.strictEqual(RegExp.$_, ''); | ||
assert.strictEqual(RegExp.$0, undefined); | ||
assert.strictEqual(RegExp.$1, ''); | ||
assert.strictEqual(RegExp.$2, ''); | ||
assert.strictEqual(RegExp.$3, ''); | ||
assert.strictEqual(RegExp.$4, ''); | ||
assert.strictEqual(RegExp.$5, ''); | ||
assert.strictEqual(RegExp.$6, ''); | ||
assert.strictEqual(RegExp.$7, ''); | ||
assert.strictEqual(RegExp.$8, ''); | ||
assert.strictEqual(RegExp.$9, ''); | ||
assert.strictEqual(RegExp.input, ''); | ||
assert.strictEqual(RegExp.lastMatch, ''); | ||
assert.strictEqual(RegExp.lastParen, ''); | ||
assert.strictEqual(RegExp.leftContext, ''); | ||
assert.strictEqual(RegExp.rightContext, ''); | ||
assert.strictEqual(RegExp['$&'], ''); | ||
assert.strictEqual(RegExp['$`'], ''); | ||
assert.strictEqual(RegExp['$+'], ''); | ||
assert.strictEqual(RegExp["$'"], ''); | ||
|
||
const allRegExpStatics = | ||
'RegExp.$_ + RegExp["$&"] + RegExp["$`"] + RegExp["$+"] + RegExp["$\'"] + ' + | ||
'RegExp.input + RegExp.lastMatch + RegExp.lastParen + ' + | ||
'RegExp.leftContext + RegExp.rightContext + ' + | ||
Array.from({ length: 10 }, (_, i) => `RegExp.$${i}`).join(' + '); | ||
|
||
{ | ||
const child = spawnSync(process.execPath, | ||
[ '-p', allRegExpStatics ], | ||
{ stdio: ['inherit', 'pipe', 'inherit'] }); | ||
assert.match(child.stdout.toString(), /^undefined\r?\n$/); | ||
assert.strictEqual(child.status, 0); | ||
assert.strictEqual(child.signal, null); | ||
} | ||
|
||
{ | ||
const child = spawnSync(process.execPath, | ||
[ '-e', `console.log(${allRegExpStatics})`, '--input-type=module' ], | ||
{ stdio: ['inherit', 'pipe', 'inherit'] }); | ||
assert.match(child.stdout.toString(), /^undefined\r?\n$/); | ||
assert.strictEqual(child.status, 0); | ||
assert.strictEqual(child.signal, null); | ||
} | ||
|
||
{ | ||
const child = spawn(process.execPath, [], { stdio: ['pipe', 'pipe', 'inherit'], encoding: 'utf8' }); | ||
|
||
let stdout = ''; | ||
child.stdout.on('data', (chunk) => { | ||
stdout += chunk; | ||
}); | ||
|
||
child.on('exit', common.mustCall((status, signal) => { | ||
assert.match(stdout, /^undefined\r?\n$/); | ||
assert.strictEqual(status, 0); | ||
assert.strictEqual(signal, null); | ||
})); | ||
child.on('error', common.mustNotCall()); | ||
|
||
child.stdin.end(`console.log(${allRegExpStatics});\n`); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// We must load the CJS version here because the ESM wrapper call `hasIPv6` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ESM There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure it's worth it, loading the CJS file seems to be enough – IMO it's unlikely that any other test would be impacted by that. |
||
// which compiles a RegEx. | ||
// eslint-disable-next-line node-core/require-common-first | ||
import '../common/index.js'; | ||
import assert from 'node:assert'; | ||
|
||
assert.strictEqual(RegExp.$_, ''); | ||
assert.strictEqual(RegExp.$0, undefined); | ||
assert.strictEqual(RegExp.$1, ''); | ||
assert.strictEqual(RegExp.$2, ''); | ||
assert.strictEqual(RegExp.$3, ''); | ||
assert.strictEqual(RegExp.$4, ''); | ||
assert.strictEqual(RegExp.$5, ''); | ||
assert.strictEqual(RegExp.$6, ''); | ||
assert.strictEqual(RegExp.$7, ''); | ||
assert.strictEqual(RegExp.$8, ''); | ||
assert.strictEqual(RegExp.$9, ''); | ||
assert.strictEqual(RegExp.input, ''); | ||
assert.strictEqual(RegExp.lastMatch, ''); | ||
assert.strictEqual(RegExp.lastParen, ''); | ||
assert.strictEqual(RegExp.leftContext, ''); | ||
assert.strictEqual(RegExp.rightContext, ''); | ||
assert.strictEqual(RegExp['$&'], ''); | ||
assert.strictEqual(RegExp['$`'], ''); | ||
assert.strictEqual(RegExp['$+'], ''); | ||
assert.strictEqual(RegExp["$'"], ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it’d be a preexisting bug but this exec could be null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR, I'll leave it as that.