Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2020-03-10 20:17:14 +0300
committerGitHub <noreply@github.com>2020-03-10 20:17:14 +0300
commitd12f79a4d1b908636b96005fe30f547e54cea3ee (patch)
tree96b2edf314b50c82622dea8c04a388bc7318d797
parentfb01e2c315731d5b03eac2f92fb1f57949620557 (diff)
Fix overaggressive CanBeMadeAtomic check for Set + Notone (#33409)v5.0.0-preview.2.20160.6
We're erroneously converting a set loop to be atomic when it's followed by a notone where the notone's character is in the set. But if we for example have `[ab]*[^a]`, we can't make the loop atomic, because the `[ab]*` can actually give back something (a `b`) that the `[^a]` will match. The fix is simply to delete the erroneous, overaggressive checks.
-rw-r--r--src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexNode.cs4
-rw-r--r--src/libraries/System.Text.RegularExpressions/tests/Regex.Groups.Tests.cs2
-rw-r--r--src/libraries/System.Text.RegularExpressions/tests/RegexReductionTests.cs4
3 files changed, 6 insertions, 4 deletions
diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexNode.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexNode.cs
index a6c53a0739f..8ba5abde70b 100644
--- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexNode.cs
+++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexNode.cs
@@ -1541,10 +1541,6 @@ namespace System.Text.RegularExpressions
case Onelazy when subsequent.M > 0 && !RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
case Oneloop when subsequent.M > 0 && !RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
case Oneloopatomic when subsequent.M > 0 && !RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
- case Notone when RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
- case Notonelazy when subsequent.M > 0 && RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
- case Notoneloop when subsequent.M > 0 && RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
- case Notoneloopatomic when subsequent.M > 0 && RegexCharClass.CharInClass(subsequent.Ch, node.Str!):
case Multi when !RegexCharClass.CharInClass(subsequent.Str![0], node.Str!):
case Set when !RegexCharClass.MayOverlap(node.Str!, subsequent.Str!):
case Setlazy when subsequent.M > 0 && !RegexCharClass.MayOverlap(node.Str!, subsequent.Str!):
diff --git a/src/libraries/System.Text.RegularExpressions/tests/Regex.Groups.Tests.cs b/src/libraries/System.Text.RegularExpressions/tests/Regex.Groups.Tests.cs
index 4a3800730b7..2c31d515b6a 100644
--- a/src/libraries/System.Text.RegularExpressions/tests/Regex.Groups.Tests.cs
+++ b/src/libraries/System.Text.RegularExpressions/tests/Regex.Groups.Tests.cs
@@ -733,6 +733,8 @@ namespace System.Text.RegularExpressions.Tests
yield return new object[] { null, @"(?:a{2}?){3}?", "aaaaaaaaa", RegexOptions.None, new string[] { "aaaaaa" } };
yield return new object[] { null, @"(?:(?:[ab]c[de]f){3}){2}", "acdfbcdfacefbcefbcefbcdfacdef", RegexOptions.None, new string[] { "acdfbcdfacefbcefbcefbcdf" } };
yield return new object[] { null, @"(?:(?:[ab]c[de]f){3}hello){2}", "aaaaaacdfbcdfacefhellobcefbcefbcdfhellooooo", RegexOptions.None, new string[] { "acdfbcdfacefhellobcefbcefbcdfhello" } };
+ yield return new object[] { null, @"CN=(.*[^,]+).*", "CN=localhost", RegexOptions.Singleline, new string[] { "CN=localhost", "localhost" } };
+
// Nested atomic
yield return new object[] { null, @"(?>abc[def]gh(i*))", "123abceghiii456", RegexOptions.None, new string[] { "abceghiii", "iii" } };
diff --git a/src/libraries/System.Text.RegularExpressions/tests/RegexReductionTests.cs b/src/libraries/System.Text.RegularExpressions/tests/RegexReductionTests.cs
index ebe9a2c902a..a70d9d1dbc8 100644
--- a/src/libraries/System.Text.RegularExpressions/tests/RegexReductionTests.cs
+++ b/src/libraries/System.Text.RegularExpressions/tests/RegexReductionTests.cs
@@ -375,6 +375,10 @@ namespace System.Text.RegularExpressions.Tests
[InlineData("a*a*?", "a*")]
[InlineData("a*?a*", "a*")]
[InlineData("a*[^a]*", "a*")]
+ [InlineData("[ab]*[^a]", "(?>[ab]*)[^a]")]
+ [InlineData("[ab]*[^a]*", "(?>[ab]*)[^a]*")]
+ [InlineData("[ab]*[^a]*?", "(?>[ab]*)[^a]*?")]
+ [InlineData("[ab]*(?>[^a]*)", "(?>[ab]*)(?>[^a]*)")]
[InlineData("[^a]*a*", "a*")]
[InlineData("a{2147483646}a", "a{2147483647}")]
[InlineData("a{2147483647}a", "a{2147483647}")]