Parse [^] when ecmascript is set
authorPrashanth Govindarajan <prgovi@microsoft.com>
Tue, 17 Dec 2019 21:15:27 +0000 (13:15 -0800)
committerPrashanth Govindarajan <prgovi@microsoft.com>
Tue, 17 Dec 2019 21:15:27 +0000 (13:15 -0800)
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParser.cs
src/libraries/System.Text.RegularExpressions/tests/Regex.MultipleMatches.Tests.cs
src/libraries/System.Text.RegularExpressions/tests/RegexParserTests.cs

index 4f3ae32..edfe8bc 100644 (file)
@@ -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)
index da03141..321ffe5 100644 (file)
@@ -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]
index a0d4e0d..aa108fd 100644 (file)
@@ -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);
-        }
     }
 }