Prevent duplicate regex flags (#7617)

This commit is contained in:
Brian Ng 2018-03-22 10:25:26 -05:00 committed by GitHub
parent e80488f1d5
commit 840ba187a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 7 deletions

View File

@ -20,6 +20,8 @@ import {
} from "../util/whitespace";
import State from "./state";
const VALID_REGEX_FLAGS = "gmsiyu";
// The following character codes are forbidden from being
// an immediate sibling of NumericLiteralSeparator _
@ -834,19 +836,24 @@ export default class Tokenizer extends LocationParser {
const content = this.input.slice(start, this.state.pos);
++this.state.pos;
const validFlags = /^[gmsiyu]$/;
let mods = "";
while (this.state.pos < this.input.length) {
const char = this.input[this.state.pos];
const charCode = this.fullCharCodeAtPos();
if (validFlags.test(char)) {
if (VALID_REGEX_FLAGS.indexOf(char) > -1) {
if (mods.indexOf(char) > -1) {
this.raise(this.state.pos + 1, "Duplicate regular expression flag");
}
++this.state.pos;
mods += char;
} else if (
isIdentifierChar(charCode) ||
charCode === charCodes.backslash
) {
this.raise(this.state.pos, "Invalid regular expression flag");
this.raise(this.state.pos + 1, "Invalid regular expression flag");
} else {
break;
}

View File

@ -1,3 +1,3 @@
{
"throws": "Invalid regular expression flag (1:16)"
"throws": "Invalid regular expression flag (1:17)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Invalid regular expression flag (1:15)"
"throws": "Invalid regular expression flag (1:16)"
}

View File

@ -0,0 +1 @@
/./gii;

View File

@ -0,0 +1,3 @@
{
"throws": "Duplicate regular expression flag (1:6)"
}

View File

@ -1946,8 +1946,6 @@ language/global-code/new.target-arrow.js(default)
language/global-code/new.target-arrow.js(strict mode)
language/import/dup-bound-names.js(default)
language/import/dup-bound-names.js(strict mode)
language/literals/regexp/early-err-dup-flag.js(default)
language/literals/regexp/early-err-dup-flag.js(strict mode)
language/literals/regexp/early-err-pattern.js(default)
language/literals/regexp/early-err-pattern.js(strict mode)
language/literals/regexp/invalid-braced-quantifier-exact.js(default)