Skip to content

Commit

Permalink
Merge pull request #993 from pgovind/RegEx
Browse files Browse the repository at this point in the history
Parse RegEx such as "[^]"
  • Loading branch information
Prashanth Govindarajan authored Dec 19, 2019
2 parents 0a29c61 + fad9533 commit 8e51dc3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@ private RegexNode ScanReplacement()
{
charClass!.Negate = true;
}
if ((_options & RegexOptions.ECMAScript) != 0 && CharAt(_currentPos) == ']')
{
firstChar = false;
}
}

for (; CharsRight() > 0; firstChar = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ public static IEnumerable<object[]> Matches_TestData()
new CaptureData("C789", 10, 4),
}
};

yield return new object[]
{
"[^]", "every", RegexOptions.ECMAScript,
new CaptureData[]
{
new CaptureData("e", 0, 1),
new CaptureData("v", 1, 1),
new CaptureData("e", 2, 1),
new CaptureData("r", 3, 1),
new CaptureData("y", 4, 1),
}
};
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ static RegexParserTests()
[InlineData(@"\d{2147483648}", RegexOptions.None, RegexParseError.CaptureGroupOutOfRange)]
[InlineData("[a-z-[b][", RegexOptions.None, RegexParseError.UnterminatedBracket)]
[InlineData("(?()|||||)", RegexOptions.None, RegexParseError.TooManyAlternates)]
[InlineData("[^]", RegexOptions.None, RegexParseError.UnterminatedBracket)]
public void Parse(string pattern, RegexOptions options, object errorObj)
{
RegexParseError? error = (RegexParseError?)errorObj;
Expand Down

0 comments on commit 8e51dc3

Please sign in to comment.