Skip to content

Commit

Permalink
report invalid RegEx flags eagerly
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed May 28, 2019
1 parent dd5b4b9 commit 715a6c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/Esprima/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,17 +1474,8 @@ public Regex TestRegExp(string pattern, string flags)
tmp = Regex.Replace(tmp, "[\uD800-\uDBFF][\uDC00-\uDFFF]", astralSubstitute);
}

RegexOptions options = RegexOptions.ECMAScript;

// First, detect invalid regular expressions.
try
{
options = ParseRegexOptions(flags);
}
catch
{
return null;
}
var options = ParseRegexOptions(flags);

try
{
Expand Down
7 changes: 7 additions & 0 deletions test/Esprima.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,12 @@ public void CanParseDot(string script)
var parser = new JavaScriptParser(script);
Assert.Throws<ParserException>(() => parser.ParseProgram());
}

[Fact]
public void ThrowsErrorForInvalidRegExFlags()
{
var parser = new JavaScriptParser("/'/o//'///C//ÿ");
Assert.Throws<ParserException>(() => parser.ParseProgram());
}
}
}

0 comments on commit 715a6c9

Please sign in to comment.