GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(javascript): refuse an unterminated literal before validating a r… · webpack/webpack@a6a167a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/javascript
    • regexp.js
  • test/unitCases/javascript
    • parser.unittest.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/javascript/regexp.js‎

Copy file name to clipboardExpand all lines: lib/javascript/regexp.js
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,28 @@ const install = (target) => {
18021802
*/
18031803
const validateRegExpLiteral = (pattern, flags, ecmaVersion) => {
18041804
const validator = new RegExpValidator({ ecmaVersion }, "");
1805+
// What a parse's scan refuses before validating, as the validator expects a
1806+
// literal it ended: a line break, a `/` ending it early, an open class or escape.
1807+
let escaped = false;
1808+
let inClass = false;
1809+
for (let i = 0; i < pattern.length; i++) {
1810+
const code = pattern.charCodeAt(i);
1811+
if (code === 10 || code === 13 || code === 0x2028 || code === 0x2029) {
1812+
validator.raise(0, "Unterminated regular expression");
1813+
}
1814+
if (escaped) {
1815+
escaped = false;
1816+
} else if (code === 92) {
1817+
escaped = true;
1818+
} else if (code === 91) {
1819+
inClass = true;
1820+
} else if (code === 93) {
1821+
inClass = false;
1822+
} else if (code === 47 && !inClass) {
1823+
validator.raise(0, "Unterminated regular expression");
1824+
}
1825+
}
1826+
if (escaped || inClass) validator.raise(0, "Unterminated regular expression");
18051827
const state = new RegExpValidationState(validator);
18061828
state.reset(0, pattern, flags);
18071829
validator.validateRegExpFlags(state);
Collapse file

‎test/unitCases/javascript/parser.unittest.js‎

Copy file name to clipboardExpand all lines: test/unitCases/javascript/parser.unittest.js
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6227,7 +6227,12 @@ describe("validateRegExpLiteral", () => {
62276227
["a", "gg", 2018, "Duplicate regular expression flag"],
62286228
["[a-z]", "v", 2018, "Invalid regular expression flag"],
62296229
["\\p{L}", "u", 2018, undefined],
6230-
["(", "", "latest", "Unterminated group"]
6230+
["(", "", "latest", "Unterminated group"],
6231+
["[", "g", 2018, "Unterminated regular expression"],
6232+
["a\\", "", 2018, "Unterminated regular expression"],
6233+
["a/b", "", 2018, "Unterminated regular expression"],
6234+
["[/]", "", 2018, undefined],
6235+
["a\nb", "", 2018, "Unterminated regular expression"]
62316236
])
62326237
)("holds /%s/%s at %s to the spec", (pattern, flags, ecmaVersion, error) => {
62336238
const validate = () => validateRegExpLiteral(pattern, flags, ecmaVersion);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.