From: Prashanth Govindarajan Date: Tue, 17 Dec 2019 21:15:27 +0000 (-0800) Subject: Parse [^] when ecmascript is set X-Git-Tag: submit/tizen/20210909.063632~10632^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52872ac36eee15ec5227ad52fa780b4013de6f7f;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Parse [^] when ecmascript is set --- diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParser.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParser.cs index 4f3ae32..edfe8bc 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParser.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParser.cs @@ -562,6 +562,10 @@ namespace System.Text.RegularExpressions { charClass!.Negate = true; } + if ((_options & RegexOptions.ECMAScript) != 0 && CharAt(_currentPos) == ']') + { + firstChar = false; + } } for (; CharsRight() > 0; firstChar = false) diff --git a/src/libraries/System.Text.RegularExpressions/tests/Regex.MultipleMatches.Tests.cs b/src/libraries/System.Text.RegularExpressions/tests/Regex.MultipleMatches.Tests.cs index da03141..321ffe5 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/Regex.MultipleMatches.Tests.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/Regex.MultipleMatches.Tests.cs @@ -140,6 +140,19 @@ namespace System.Text.RegularExpressions.Tests 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] diff --git a/src/libraries/System.Text.RegularExpressions/tests/RegexParserTests.cs b/src/libraries/System.Text.RegularExpressions/tests/RegexParserTests.cs index a0d4e0d..aa108fd 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/RegexParserTests.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/RegexParserTests.cs @@ -882,13 +882,5 @@ namespace System.Text.RegularExpressions.Tests throw new XunitException($"Expected RegexParseException with error: ({error}) -> Actual: No exception thrown"); } - - [Fact] - public void TestPattern() - { - Debugger.Launch(); - string pattern = @"[b-\-a]"; - var regex = new Regex(pattern); - } } }