Skip to content

Commit 4668546

Browse files
authored
Escape dashes in RegexCharClass.DescribeSet (#117909)
1 parent 91f4d57 commit 4668546

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,7 @@ public static string DescribeChar(char ch) =>
21352135
'\f' => "\\f",
21362136
'\n' => "\\n",
21372137
'\\' => "\\\\",
2138+
'-' => "\\-",
21382139
>= ' ' and <= '~' => ch.ToString(),
21392140
_ => $"\\u{(uint)ch:X4}"
21402141
};

src/libraries/System.Text.RegularExpressions/tests/UnitTests/RegexCharClassTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class RegexCharClassTests
2828
[InlineData(@"[\p{IsGreek}]", @"[\u0370-\u03FF]")]
2929
[InlineData(@"[\0-ad-\uFFFF]", @"[^bc]")]
3030
[InlineData(@"[\0-ad-\uFFFF-[a-d]]", @"[\0-ad-\uFFFF-[a-d]]")]
31+
[InlineData(@"[- _,|]", @"[ ,\-_|]")]
3132
public void DescribeSet(string set, string expected)
3233
{
3334
RegexNode setNode = RegexParser.Parse($"{set}", RegexOptions.None, CultureInfo.InvariantCulture).Root.Child(0);

0 commit comments

Comments
 (0)