Skip to content

Commit f98389c

Browse files
authored
remove [::] treatment (#88590)
1 parent 4e48d2d commit f98389c

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParser.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -668,21 +668,6 @@ private RegexNode ScanReplacement()
668668
break; // this break will only break out of the switch
669669
}
670670
}
671-
else if (ch == '[')
672-
{
673-
// This is code for Posix style properties - [:Ll:] or [:IsTibetan:].
674-
// It currently doesn't do anything other than skip the whole thing!
675-
if (_pos < _pattern.Length && _pattern[_pos] == ':' && !inRange)
676-
{
677-
int savePos = _pos;
678-
679-
_pos++;
680-
if (_pos + 1 >= _pattern.Length || _pattern[_pos++] != ':' || _pattern[_pos++] != ']')
681-
{
682-
_pos = savePos;
683-
}
684-
}
685-
}
686671

687672
if (inRange)
688673
{

src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Match.Tests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,15 @@ public static IEnumerable<object[]> Match_MemberData()
917917
yield return (@"^(?i:[\u24B6-\u24D0])$", ((char)('\u24CF' + 26)).ToString(), RegexOptions.IgnoreCase | RegexOptions.CultureInvariant, 0, 1, true, ((char)('\u24CF' + 26)).ToString());
918918
}
919919

920+
// [:XX:] inside a range has no special treatment; the [:XX: is literal, the ] closes the range
921+
if (PlatformDetection.IsNetCore)
922+
{
923+
yield return (@"[[::]]", "x", RegexOptions.None, 0, 1, false, "");
924+
yield return (@"[[:a:]]", "a]", RegexOptions.None, 0, 2, true, "a]");
925+
yield return (@"[c[:ab:]", "c", RegexOptions.None, 0, 1, true, "c");
926+
yield return (@"[c[:ab:]{3}d]", "abcd]", RegexOptions.None, 0, 5, true, "abcd]");
927+
}
928+
920929
// Long inputs
921930
string longCharacterRange = string.Concat(Enumerable.Range(1, 0x2000).Select(c => (char)c));
922931
foreach (RegexOptions options in new[] { RegexOptions.None, RegexOptions.IgnoreCase })

src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexParserTests.netcoreapp.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public partial class RegexParserTests
8585
[InlineData("a{0,2147483648}", RegexOptions.None, RegexParseError.QuantifierOrCaptureGroupOutOfRange, 14)]
8686
// Surrogate pair which is parsed as [char,char-char,char] as we operate on UTF-16 code units.
8787
[InlineData("[\uD82F\uDCA0-\uD82F\uDCA3]", RegexOptions.IgnoreCase, RegexParseError.ReversedCharacterRange, 5)]
88+
// [ inside a range is treated literally
89+
[InlineData(@"[[::]", RegexOptions.None, null)]
90+
[InlineData(@"[[:X:]", RegexOptions.None, null)]
91+
[InlineData(@"[[:ab:]", RegexOptions.None, null)]
8892

8993
// Following are borrowed from Rust regex tests ============
9094
// https://github.com/rust-lang/regex/blob/master/tests/noparse.rs

0 commit comments

Comments
 (0)