-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: reset
RegExp
statics before running user code
Fixes: #43740 PR-URL: #43741 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
11 changed files
with
136 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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'); | ||
|
||
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`); | ||
} |
This file contains 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
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` | ||
// 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["$'"], ''); |
This file contains 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
This file contains 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