From 52872ac36eee15ec5227ad52fa780b4013de6f7f Mon Sep 17 00:00:00 2001 From: Prashanth Govindarajan Date: Tue, 17 Dec 2019 13:15:27 -0800 Subject: [PATCH] Parse [^] when ecmascript is set --- .../src/System/Text/RegularExpressions/RegexParser.cs | 4 ++++ .../tests/Regex.MultipleMatches.Tests.cs | 13 +++++++++++++ .../tests/RegexParserTests.cs | 8 -------- 3 files changed, 17 insertions(+), 8 deletions(-) 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); - } } } -- 2.7.4