From 32480f56930e39a469b0bc560003e55fd775ac8d Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sun, 24 Mar 2024 19:10:26 -0400 Subject: [PATCH] Use \e instead of \u001B or \x1B --- .../src/AnsiParser.cs | 56 +++++++++---------- .../AnsiParserTests.cs | 56 +++++++++---------- .../TextWriterExtensionsTests.cs | 8 +-- .../System.Console/src/System/IO/KeyParser.cs | 2 +- .../src/System/TerminalFormatStrings.cs | 10 ++-- .../System.Console/tests/KeyParserTests.cs | 44 +++++++-------- .../System.Console/tests/TermInfo.Unix.cs | 36 ++++++------ .../Strings/StringSearchValues.cs | 2 +- .../Text/RegularExpressions/RegexParser.cs | 2 +- .../FunctionalTests/Regex.Groups.Tests.cs | 4 +- .../tests/FunctionalTests/RegexPcreTests.cs | 2 +- 11 files changed, 111 insertions(+), 111 deletions(-) diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/src/AnsiParser.cs b/src/libraries/Microsoft.Extensions.Logging.Console/src/AnsiParser.cs index 4e8725118b1f1..71ea987bff195 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/src/AnsiParser.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Console/src/AnsiParser.cs @@ -50,7 +50,7 @@ public void Parse(string message) ConsoleColor? foreground = null; ConsoleColor? background = null; var span = message.AsSpan(); - const char EscapeChar = '\x1B'; + const char EscapeChar = '\e'; ConsoleColor? color = null; bool isBright = false; for (int i = 0; i < span.Length; i++) @@ -59,7 +59,7 @@ public void Parse(string message) { if (span[i + 3] == 'm') { - // Example: \x1B[1m + // Example: \e[1m if (IsDigit(span[i + 2])) { escapeCode = (int)(span[i + 2] - '0'); @@ -77,7 +77,7 @@ public void Parse(string message) } else if (span.Length >= i + 5 && span[i + 4] == 'm') { - // Example: \x1B[40m + // Example: \e[40m if (IsDigit(span[i + 2]) && IsDigit(span[i + 3])) { escapeCode = (int)(span[i + 2] - '0') * 10 + (int)(span[i + 3] - '0'); @@ -127,28 +127,28 @@ public void Parse(string message) [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool IsDigit(char c) => (uint)(c - '0') <= ('9' - '0'); - internal const string DefaultForegroundColor = "\x1B[39m\x1B[22m"; // reset to default foreground color - internal const string DefaultBackgroundColor = "\x1B[49m"; // reset to the background color + internal const string DefaultForegroundColor = "\e[39m\e[22m"; // reset to default foreground color + internal const string DefaultBackgroundColor = "\e[49m"; // reset to the background color internal static string GetForegroundColorEscapeCode(ConsoleColor color) { return color switch { - ConsoleColor.Black => "\x1B[30m", - ConsoleColor.DarkRed => "\x1B[31m", - ConsoleColor.DarkGreen => "\x1B[32m", - ConsoleColor.DarkYellow => "\x1B[33m", - ConsoleColor.DarkBlue => "\x1B[34m", - ConsoleColor.DarkMagenta => "\x1B[35m", - ConsoleColor.DarkCyan => "\x1B[36m", - ConsoleColor.Gray => "\x1B[37m", - ConsoleColor.Red => "\x1B[1m\x1B[31m", - ConsoleColor.Green => "\x1B[1m\x1B[32m", - ConsoleColor.Yellow => "\x1B[1m\x1B[33m", - ConsoleColor.Blue => "\x1B[1m\x1B[34m", - ConsoleColor.Magenta => "\x1B[1m\x1B[35m", - ConsoleColor.Cyan => "\x1B[1m\x1B[36m", - ConsoleColor.White => "\x1B[1m\x1B[37m", + ConsoleColor.Black => "\e[30m", + ConsoleColor.DarkRed => "\e[31m", + ConsoleColor.DarkGreen => "\e[32m", + ConsoleColor.DarkYellow => "\e[33m", + ConsoleColor.DarkBlue => "\e[34m", + ConsoleColor.DarkMagenta => "\e[35m", + ConsoleColor.DarkCyan => "\e[36m", + ConsoleColor.Gray => "\e[37m", + ConsoleColor.Red => "\e[1m\e[31m", + ConsoleColor.Green => "\e[1m\e[32m", + ConsoleColor.Yellow => "\e[1m\e[33m", + ConsoleColor.Blue => "\e[1m\e[34m", + ConsoleColor.Magenta => "\e[1m\e[35m", + ConsoleColor.Cyan => "\e[1m\e[36m", + ConsoleColor.White => "\e[1m\e[37m", _ => DefaultForegroundColor // default foreground color }; } @@ -157,14 +157,14 @@ internal static string GetBackgroundColorEscapeCode(ConsoleColor color) { return color switch { - ConsoleColor.Black => "\x1B[40m", - ConsoleColor.DarkRed => "\x1B[41m", - ConsoleColor.DarkGreen => "\x1B[42m", - ConsoleColor.DarkYellow => "\x1B[43m", - ConsoleColor.DarkBlue => "\x1B[44m", - ConsoleColor.DarkMagenta => "\x1B[45m", - ConsoleColor.DarkCyan => "\x1B[46m", - ConsoleColor.Gray => "\x1B[47m", + ConsoleColor.Black => "\e[40m", + ConsoleColor.DarkRed => "\e[41m", + ConsoleColor.DarkGreen => "\e[42m", + ConsoleColor.DarkYellow => "\e[43m", + ConsoleColor.DarkBlue => "\e[44m", + ConsoleColor.DarkMagenta => "\e[45m", + ConsoleColor.DarkCyan => "\e[46m", + ConsoleColor.Gray => "\e[47m", _ => DefaultBackgroundColor // Use default background color }; } diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/tests/Microsoft.Extensions.Logging.Console.Tests/AnsiParserTests.cs b/src/libraries/Microsoft.Extensions.Logging.Console/tests/Microsoft.Extensions.Logging.Console.Tests/AnsiParserTests.cs index 74d04894eba40..215535c8efb9e 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/tests/Microsoft.Extensions.Logging.Console.Tests/AnsiParserTests.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Console/tests/Microsoft.Extensions.Logging.Console.Tests/AnsiParserTests.cs @@ -11,12 +11,12 @@ namespace Microsoft.Extensions.Logging.Console.Test { public class AnsiParserTests { - private const char EscapeChar = '\x1B'; + private const char EscapeChar = '\e'; [Theory] [InlineData(1, "No Color", "No Color")] - [InlineData(2, "\x1B[41mColored\x1B[49mNo Color", "No Color")] - [InlineData(2, "\x1B[41m\x1B[1m\x1B[31mmColored\x1B[39m\x1B[49mNo Color", "No Color")] + [InlineData(2, "\e[41mColored\e[49mNo Color", "No Color")] + [InlineData(2, "\e[41m\e[1m\e[31mmColored\e[39m\e[49mNo Color", "No Color")] public void Parse_CheckTimesWrittenToConsole(int numSegments, string message, string lastSegment) { // Arrange @@ -151,33 +151,33 @@ public void Parse_RepeatedColorChange_PicksLastSet() [Theory] // supported - [InlineData("\x1B[77mInfo", "Info")] - [InlineData("\x1B[77m\x1B[1m\x1B[2m\x1B[0mInfo\x1B[1m", "Info")] - [InlineData("\x1B[7mInfo", "Info")] - [InlineData("\x1B[40m\x1B[1m\x1B[33mwarn\x1B[39m\x1B[22m\x1B[49m:", "warn", ":")] + [InlineData("\e[77mInfo", "Info")] + [InlineData("\e[77m\e[1m\e[2m\e[0mInfo\e[1m", "Info")] + [InlineData("\e[7mInfo", "Info")] + [InlineData("\e[40m\e[1m\e[33mwarn\e[39m\e[22m\e[49m:", "warn", ":")] // unsupported: skips - [InlineData("Info\x1B[77m:", "Info", ":")] - [InlineData("Info\x1B[7m:", "Info", ":")] + [InlineData("Info\e[77m:", "Info", ":")] + [InlineData("Info\e[7m:", "Info", ":")] // treats as content - [InlineData("\x1B", "\x1B")] - [InlineData("\x1B ", "\x1B ")] - [InlineData("\x1Bm", "\x1Bm")] - [InlineData("\x1B m", "\x1B m")] - [InlineData("\x1Bxym", "\x1Bxym")] - [InlineData("\x1B[", "\x1B[")] - [InlineData("\x1B[m", "\x1B[m")] - [InlineData("\x1B[ ", "\x1B[ ")] - [InlineData("\x1B[ m", "\x1B[ m")] - [InlineData("\x1B[xym", "\x1B[xym")] - [InlineData("\x1B[7777m", "\x1B[7777m")] - [InlineData("\x1B\x1B\x1B", "\x1B\x1B\x1B")] - [InlineData("Message\x1B\x1B\x1B", "Message\x1B\x1B\x1B")] - [InlineData("\x1B\x1BMessage\x1B", "\x1B\x1BMessage\x1B")] - [InlineData("\x1B\x1B\x1BMessage", "\x1B\x1B\x1BMessage")] - [InlineData("Message\x1B ", "Message\x1B ")] - [InlineData("\x1BmMessage", "\x1BmMessage")] - [InlineData("\x1B[77m\x1B m\x1B[40m", "\x1B m")] - [InlineData("\x1B mMessage\x1Bxym", "\x1B mMessage\x1Bxym")] + [InlineData("\e", "\e")] + [InlineData("\e ", "\e ")] + [InlineData("\em", "\em")] + [InlineData("\e m", "\e m")] + [InlineData("\exym", "\exym")] + [InlineData("\e[", "\e[")] + [InlineData("\e[m", "\e[m")] + [InlineData("\e[ ", "\e[ ")] + [InlineData("\e[ m", "\e[ m")] + [InlineData("\e[xym", "\e[xym")] + [InlineData("\e[7777m", "\e[7777m")] + [InlineData("\e\e\e", "\e\e\e")] + [InlineData("Message\e\e\e", "Message\e\e\e")] + [InlineData("\e\eMessage\e", "\e\eMessage\e")] + [InlineData("\e\e\eMessage", "\e\e\eMessage")] + [InlineData("Message\e ", "Message\e ")] + [InlineData("\emMessage", "\emMessage")] + [InlineData("\e[77m\e m\e[40m", "\e m")] + [InlineData("\e mMessage\exym", "\e mMessage\exym")] public void Parse_ValidSupportedOrUnsupportedCodesInMessage_MessageParsedSuccessfully(string messageWithUnsupportedCode, params string[] output) { // Arrange diff --git a/src/libraries/Microsoft.Extensions.Logging.Console/tests/Microsoft.Extensions.Logging.Console.Tests/TextWriterExtensionsTests.cs b/src/libraries/Microsoft.Extensions.Logging.Console/tests/Microsoft.Extensions.Logging.Console.Tests/TextWriterExtensionsTests.cs index 3c6520ebb9bfc..79c1d6b14ea99 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Console/tests/Microsoft.Extensions.Logging.Console.Tests/TextWriterExtensionsTests.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Console/tests/Microsoft.Extensions.Logging.Console.Tests/TextWriterExtensionsTests.cs @@ -16,7 +16,7 @@ public void WriteColoredMessage_WithForegroundEscapeCode_AndNoBackgroundColorSpe var message = "Request received"; var expectedMessage = AnsiParser.GetForegroundColorEscapeCode(ConsoleColor.DarkGreen) + message - + "\x1B[39m\x1B[22m"; //resets foreground color + + "\e[39m\e[22m"; //resets foreground color var textWriter = new StringWriter(); // Act @@ -33,7 +33,7 @@ public void WriteColoredMessage_WithBackgroundEscapeCode_AndNoForegroundColorSpe var message = "Request received"; var expectedMessage = AnsiParser.GetBackgroundColorEscapeCode(ConsoleColor.Red) + message - + "\x1B[49m"; //resets background color + + "\e[49m"; //resets background color var textWriter = new StringWriter(); // Act @@ -51,8 +51,8 @@ public void WriteColoredMessage_InOrder_WhenBothForegroundOrBackgroundColorsSpec var expectedMessage = AnsiParser.GetBackgroundColorEscapeCode(ConsoleColor.Red) + AnsiParser.GetForegroundColorEscapeCode(ConsoleColor.DarkGreen) + "Request received" - + "\x1B[39m\x1B[22m" //resets foreground color - + "\x1B[49m"; //resets background color + + "\e[39m\e[22m" //resets foreground color + + "\e[49m"; //resets background color var textWriter = new StringWriter(); // Act diff --git a/src/libraries/System.Console/src/System/IO/KeyParser.cs b/src/libraries/System.Console/src/System/IO/KeyParser.cs index fd09e7fe227ee..23326d485d497 100644 --- a/src/libraries/System.Console/src/System/IO/KeyParser.cs +++ b/src/libraries/System.Console/src/System/IO/KeyParser.cs @@ -8,7 +8,7 @@ namespace System.IO; internal static class KeyParser { - private const char Escape = '\u001B'; + private const char Escape = '\e'; private const char Delete = '\u007F'; private const char VtSequenceEndTag = '~'; private const char ModifierSeparator = ';'; diff --git a/src/libraries/System.Console/src/System/TerminalFormatStrings.cs b/src/libraries/System.Console/src/System/TerminalFormatStrings.cs index e4e0392d82b11..a1f194184a09e 100644 --- a/src/libraries/System.Console/src/System/TerminalFormatStrings.cs +++ b/src/libraries/System.Console/src/System/TerminalFormatStrings.cs @@ -46,7 +46,7 @@ internal sealed class TerminalFormatStrings /// doesn't contain it (as appears to be the case with e.g. screen and tmux on Ubuntu), at the risk /// of outputting the sequence on some terminal that's not compatible. /// - public const string CursorPositionReport = "\x1B[6n"; + public const string CursorPositionReport = "\e[6n"; /// /// The dictionary of keystring to ConsoleKeyInfo. /// Only some members of the ConsoleKeyInfo are used; in particular, the actual char is ignored. @@ -210,13 +210,13 @@ private static string GetTitle(TermInfo.Database db) case "linux": case "rxvt": case "xterm": - return "\x1B]0;%p1%s\x07"; + return "\e]0;%p1%s\x07"; case "cygwin": - return "\x1B];%p1%s\x07"; + return "\e];%p1%s\x07"; case "konsole": - return "\x1B]30;%p1%s\x07"; + return "\e]30;%p1%s\x07"; case "screen": - return "\x1Bk%p1%s\x1B\\"; + return "\ek%p1%s\e\\"; default: return string.Empty; } diff --git a/src/libraries/System.Console/tests/KeyParserTests.cs b/src/libraries/System.Console/tests/KeyParserTests.cs index 557e889d2fb53..a893988995d5e 100644 --- a/src/libraries/System.Console/tests/KeyParserTests.cs +++ b/src/libraries/System.Console/tests/KeyParserTests.cs @@ -42,7 +42,7 @@ public class KeyParserTests yield return ('.', ConsoleKey.OemPeriod); yield return (',', ConsoleKey.OemComma); - yield return ('\u001B', ConsoleKey.Escape); + yield return ('\e', ConsoleKey.Escape); for (char i = '0'; i <= '9'; i++) { @@ -212,7 +212,7 @@ public void KeysAreProperlyMapped(TerminalData terminalData, byte[] recordedByte yield return (GetString(33), ConsoleKey.F19); yield return (GetString(34), ConsoleKey.F20); - static string GetString(int i) => $"\u001B[{i}~"; + static string GetString(int i) => $"\e[{i}~"; } } @@ -223,7 +223,7 @@ public static IEnumerable VTSequencesArguments [MemberData(nameof(VTSequencesArguments))] public void VTSequencesAreProperlyMapped(TerminalData terminalData, string input, ConsoleKey expectedKey) { - if (terminalData is RxvtUnicode && input == "\u001B[4~" && expectedKey == ConsoleKey.End) + if (terminalData is RxvtUnicode && input == "\e[4~" && expectedKey == ConsoleKey.End) { expectedKey = ConsoleKey.Select; // rxvt binds this key to Select in Terminfo and uses "^[[8~" for End key } @@ -239,10 +239,10 @@ public void VTSequencesAreProperlyMapped(TerminalData terminalData, string input { get { - yield return ("\u001BOa", ConsoleKey.UpArrow); - yield return ("\u001BOb", ConsoleKey.DownArrow); - yield return ("\u001BOc", ConsoleKey.RightArrow); - yield return ("\u001BOd", ConsoleKey.LeftArrow); + yield return ("\eOa", ConsoleKey.UpArrow); + yield return ("\eOb", ConsoleKey.DownArrow); + yield return ("\eOc", ConsoleKey.RightArrow); + yield return ("\eOd", ConsoleKey.LeftArrow); } } @@ -272,9 +272,9 @@ public void ExtendedStringCodePath() // Ctrl+Backspace yield return ("\b", new[] { new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, true) }); // Alt+Backspace - yield return ("\u001B\u007F", new[] { new ConsoleKeyInfo((char)0x7F, ConsoleKey.Backspace, false, true, false) }); + yield return ("\e\u007F", new[] { new ConsoleKeyInfo((char)0x7F, ConsoleKey.Backspace, false, true, false) }); // Ctrl+Alt+Backspace - yield return ("\u001B\b", new[] { new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, true, true) }); + yield return ("\e\b", new[] { new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, true, true) }); // Enter yield return ("\r", new[] { new ConsoleKeyInfo('\r', ConsoleKey.Enter, false, false, false) }); // Ctrl+Enter @@ -283,18 +283,18 @@ public void ExtendedStringCodePath() // Escape key pressed multiple times for (int i = 1; i <= 5; i++) { - yield return (new string('\u001B', i), Enumerable.Repeat(new ConsoleKeyInfo('\u001B', ConsoleKey.Escape, false, false, false), i).ToArray()); + yield return (new string('\e', i), Enumerable.Repeat(new ConsoleKeyInfo('\e', ConsoleKey.Escape, false, false, false), i).ToArray()); } // Home key (^[[H) followed by H key - yield return ("\u001B[HH", new[] + yield return ("\e[HH", new[] { new ConsoleKeyInfo(default, ConsoleKey.Home, false, false, false), new ConsoleKeyInfo('H', ConsoleKey.H, true, false, false) }); // escape sequence (F12 '^[[24~') followed by an extra tylde: - yield return ($"\u001B[24~~", new[] + yield return ($"\e[24~~", new[] { new ConsoleKeyInfo(default, ConsoleKey.F12, false, false, false), new ConsoleKeyInfo('~', default, false, false, false), @@ -304,9 +304,9 @@ public void ExtendedStringCodePath() // Invalid modifiers (valid values are <2, 8>) foreach (int invalidModifier in new[] { 0, 1, 9 }) { - yield return ($"\u001B[1;{invalidModifier}H", new[] + yield return ($"\e[1;{invalidModifier}H", new[] { - new ConsoleKeyInfo('\u001B', ConsoleKey.Escape, false, false, false), + new ConsoleKeyInfo('\e', ConsoleKey.Escape, false, false, false), new ConsoleKeyInfo('[', default, false, false, false), new ConsoleKeyInfo('1', ConsoleKey.D1, false, false, false), new ConsoleKeyInfo(';', default, false, false, false), @@ -317,9 +317,9 @@ public void ExtendedStringCodePath() // Invalid ID (valid values are <1, 34> except of 9, 16, 22, 27, 30 and 35) foreach (int invalidId in new[] { 16, 22, 27, 30, 35, 36, 77, 99 }) { - yield return ($"\u001B[{invalidId}~", new[] + yield return ($"\e[{invalidId}~", new[] { - new ConsoleKeyInfo('\u001B', ConsoleKey.Escape, false, false, false), + new ConsoleKeyInfo('\e', ConsoleKey.Escape, false, false, false), new ConsoleKeyInfo('[', default, false, false, false), new ConsoleKeyInfo((char)('0' + invalidId / 10), ConsoleKey.D0 + invalidId / 10, false, false, false), new ConsoleKeyInfo((char)('0' + invalidId % 10), ConsoleKey.D0 + invalidId % 10, false, false, false), @@ -327,9 +327,9 @@ public void ExtendedStringCodePath() }); } // too long ID (more than 2 digits) - yield return ($"\u001B[111~", new[] + yield return ($"\e[111~", new[] { - new ConsoleKeyInfo('\u001B', ConsoleKey.Escape, false, false, false), + new ConsoleKeyInfo('\e', ConsoleKey.Escape, false, false, false), new ConsoleKeyInfo('[', default, false, false, false), new ConsoleKeyInfo('1', ConsoleKey.D1, false, false, false), new ConsoleKeyInfo('1', ConsoleKey.D1, false, false, false), @@ -337,9 +337,9 @@ public void ExtendedStringCodePath() new ConsoleKeyInfo('~', default, false, false, false), }); // missing closing tag (tylde): - yield return ($"\u001B[24", new[] + yield return ($"\e[24", new[] { - new ConsoleKeyInfo('\u001B', ConsoleKey.Escape, false, false, false), + new ConsoleKeyInfo('\e', ConsoleKey.Escape, false, false, false), new ConsoleKeyInfo('[', default, false, false, false), new ConsoleKeyInfo('2', ConsoleKey.D2, false, false, false), new ConsoleKeyInfo('4', ConsoleKey.D4, false, false, false), @@ -386,7 +386,7 @@ public void NewLineEscapeSequenceProducesCharacter() { XTermData xTerm = new(); - ConsoleKeyInfo consoleKeyInfo = Parse("\u001BOM".ToCharArray(), xTerm.TerminalDb, xTerm.Verase, 3); + ConsoleKeyInfo consoleKeyInfo = Parse("\eOM".ToCharArray(), xTerm.TerminalDb, xTerm.Verase, 3); Assert.Equal(ConsoleKey.Enter, consoleKeyInfo.Key); Assert.Equal('\r', consoleKeyInfo.KeyChar); @@ -398,7 +398,7 @@ public void BackTabEscapeSequence() { XTermData xTerm = new(); - ConsoleKeyInfo consoleKeyInfo = Parse("\u001B[Z".ToCharArray(), xTerm.TerminalDb, xTerm.Verase, 3); + ConsoleKeyInfo consoleKeyInfo = Parse("\e[Z".ToCharArray(), xTerm.TerminalDb, xTerm.Verase, 3); Assert.Equal(ConsoleKey.Tab, consoleKeyInfo.Key); Assert.Equal(default, consoleKeyInfo.KeyChar); diff --git a/src/libraries/System.Console/tests/TermInfo.Unix.cs b/src/libraries/System.Console/tests/TermInfo.Unix.cs index e2fad1c0f183a..2ce7c4c9ff204 100644 --- a/src/libraries/System.Console/tests/TermInfo.Unix.cs +++ b/src/libraries/System.Console/tests/TermInfo.Unix.cs @@ -76,21 +76,21 @@ public void VerifyTermInfoSupportsNewAndLegacyNcurses() [Theory] [PlatformSpecific(TestPlatforms.AnyUnix)] // Tests TermInfo - [InlineData("xterm-256color", "\u001B\u005B\u00330m", "\u001B\u005B\u00340m", 0)] - [InlineData("xterm-256color", "\u001B\u005B\u00331m", "\u001B\u005B\u00341m", 1)] - [InlineData("xterm-256color", "\u001B\u005B90m", "\u001B\u005B100m", 8)] - [InlineData("screen", "\u001B\u005B\u00330m", "\u001B\u005B\u00340m", 0)] - [InlineData("screen", "\u001B\u005B\u00332m", "\u001B\u005B\u00342m", 2)] - [InlineData("screen", "\u001B\u005B\u00339m", "\u001B\u005B\u00349m", 9)] - [InlineData("Eterm", "\u001B\u005B\u00330m", "\u001B\u005B\u00340m", 0)] - [InlineData("Eterm", "\u001B\u005B\u00333m", "\u001B\u005B\u00343m", 3)] - [InlineData("Eterm", "\u001B\u005B\u003310m", "\u001B\u005B\u003410m", 10)] - [InlineData("wsvt25", "\u001B\u005B\u00330m", "\u001B\u005B\u00340m", 0)] - [InlineData("wsvt25", "\u001B\u005B\u00334m", "\u001B\u005B\u00344m", 4)] - [InlineData("wsvt25", "\u001B\u005B\u003311m", "\u001B\u005B\u003411m", 11)] - [InlineData("mach-color", "\u001B\u005B\u00330m", "\u001B\u005B\u00340m", 0)] - [InlineData("mach-color", "\u001B\u005B\u00335m", "\u001B\u005B\u00345m", 5)] - [InlineData("mach-color", "\u001B\u005B\u003312m", "\u001B\u005B\u003412m", 12)] + [InlineData("xterm-256color", "\e\u005B\u00330m", "\e\u005B\u00340m", 0)] + [InlineData("xterm-256color", "\e\u005B\u00331m", "\e\u005B\u00341m", 1)] + [InlineData("xterm-256color", "\e\u005B90m", "\e\u005B100m", 8)] + [InlineData("screen", "\e\u005B\u00330m", "\e\u005B\u00340m", 0)] + [InlineData("screen", "\e\u005B\u00332m", "\e\u005B\u00342m", 2)] + [InlineData("screen", "\e\u005B\u00339m", "\e\u005B\u00349m", 9)] + [InlineData("Eterm", "\e\u005B\u00330m", "\e\u005B\u00340m", 0)] + [InlineData("Eterm", "\e\u005B\u00333m", "\e\u005B\u00343m", 3)] + [InlineData("Eterm", "\e\u005B\u003310m", "\e\u005B\u003410m", 10)] + [InlineData("wsvt25", "\e\u005B\u00330m", "\e\u005B\u00340m", 0)] + [InlineData("wsvt25", "\e\u005B\u00334m", "\e\u005B\u00344m", 4)] + [InlineData("wsvt25", "\e\u005B\u003311m", "\e\u005B\u003411m", 11)] + [InlineData("mach-color", "\e\u005B\u00330m", "\e\u005B\u00340m", 0)] + [InlineData("mach-color", "\e\u005B\u00335m", "\e\u005B\u00345m", 5)] + [InlineData("mach-color", "\e\u005B\u003312m", "\e\u005B\u003412m", 12)] public void TermInfoVerification(string termToTest, string expectedForeground, string expectedBackground, int colorValue) { TermInfo.Database db = TermInfo.DatabaseFactory.ReadDatabase(termToTest); @@ -109,8 +109,8 @@ public void TermInfoClearIncludesE3WhenExpected() { // XTerm defines E3 for clearing scrollback buffer and tmux does not. // This can't be added to TermInfoVerification because xterm-256color sometimes has E3 defined (e.g. on Ubuntu but not macOS) - Assert.Equal("\u001B[H\u001B[2J\u001B[3J", new XTermData().TerminalDb.Clear); - Assert.Equal("\u001B[H\u001B[J", new TmuxData().TerminalDb.Clear); + Assert.Equal("\e[H\e[2J\e[3J", new XTermData().TerminalDb.Clear); + Assert.Equal("\e[H\e[J", new TmuxData().TerminalDb.Clear); } [Fact] @@ -119,7 +119,7 @@ public void EmuTermInfoDoesntBreakParser() { // This file (available by default on OS X) is called out specifically since it contains a format where it has %i // but only one variable instead of two. Make sure we don't break in this case - TermInfoVerification("emu", "\u001Br1;", "\u001Bs1;", 0); + TermInfoVerification("emu", "\er1;", "\es1;", 0); } [Fact] diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/StringSearchValues.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/StringSearchValues.cs index 2bff05214c518..e2ae3c61b0445 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/StringSearchValues.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/StringSearchValues.cs @@ -21,7 +21,7 @@ internal static class StringSearchValues SearchValues.Create("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); private static readonly SearchValues s_allAsciiExceptLowercase = - SearchValues.Create("\0\u0001\u0002\u0003\u0004\u0005\u0006\a\b\t\n\v\f\r\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~\u007F"); + SearchValues.Create("\0\u0001\u0002\u0003\u0004\u0005\u0006\a\b\t\n\v\f\r\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\e\u001C\u001D\u001E\u001F !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`{|}~\u007F"); public static SearchValues Create(ReadOnlySpan values, bool ignoreCase) { 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 6485f5e04659e..fc6fa74e114ba 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 @@ -1592,7 +1592,7 @@ private char ScanCharEscape() case 'b': return '\b'; case 'e': - return '\u001B'; + return '\e'; case 'f': return '\f'; case 'n': diff --git a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Groups.Tests.cs b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Groups.Tests.cs index c3ff5b595caa2..b8afa3f7aa4e3 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Groups.Tests.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Groups.Tests.cs @@ -289,7 +289,7 @@ public static IEnumerable Groups_MemberData() yield return (enUS, @"(cat)([\u0041]*)(dog)", "catAAAdog", RegexOptions.None, new string[] { "catAAAdog", "cat", "AAA", "dog" }); yield return (enUS, @"(cat)([\a]*)(dog)", "cat\a\a\adog", RegexOptions.None, new string[] { "cat\a\a\adog", "cat", "\a\a\a", "dog" }); yield return (enUS, @"(cat)([\b]*)(dog)", "cat\b\b\bdog", RegexOptions.None, new string[] { "cat\b\b\bdog", "cat", "\b\b\b", "dog" }); - yield return (enUS, @"(cat)([\e]*)(dog)", "cat\u001B\u001B\u001Bdog", RegexOptions.None, new string[] { "cat\u001B\u001B\u001Bdog", "cat", "\u001B\u001B\u001B", "dog" }); + yield return (enUS, @"(cat)([\e]*)(dog)", "cat\e\e\edog", RegexOptions.None, new string[] { "cat\e\e\edog", "cat", "\e\e\e", "dog" }); yield return (enUS, @"(cat)([\f]*)(dog)", "cat\f\f\fdog", RegexOptions.None, new string[] { "cat\f\f\fdog", "cat", "\f\f\f", "dog" }); yield return (enUS, @"(cat)([\r]*)(dog)", "cat\r\r\rdog", RegexOptions.None, new string[] { "cat\r\r\rdog", "cat", "\r\r\r", "dog" }); yield return (enUS, @"(cat)([\v]*)(dog)", "cat\v\v\vdog", RegexOptions.None, new string[] { "cat\v\v\vdog", "cat", "\v\v\v", "dog" }); @@ -433,7 +433,7 @@ public static IEnumerable Groups_MemberData() if (!PlatformDetection.IsNetFramework) // `\c[` was not handled in .NET Framework. See https://github.com/dotnet/runtime/issues/24759. { - yield return (enUS, @"(cat)(\c[*)(dog)", "asdlkcat\u001bdogiwod", RegexOptions.None, new string[] { "cat\u001bdog", "cat", "\u001b", "dog" }); + yield return (enUS, @"(cat)(\c[*)(dog)", "asdlkcat\edogiwod", RegexOptions.None, new string[] { "cat\edog", "cat", "\e", "dog" }); } // Atomic Zero-Width Assertions \A \G ^ \Z \z \b \B diff --git a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexPcreTests.cs b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexPcreTests.cs index 0063cf802fdf1..034cb108a99e1 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexPcreTests.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexPcreTests.cs @@ -37,7 +37,7 @@ public static IEnumerable PcreTestData() yield return ("The quick brown fox", RegexOptions.IgnoreCase, "The quick brown FOX", true); yield return ("The quick brown fox", RegexOptions.IgnoreCase, "What do you know about the quick brown fox?", true); yield return ("The quick brown fox", RegexOptions.IgnoreCase, "What do you know about THE QUICK BROWN FOX?", true); - yield return ("abcd\\t\\n\\r\\f\\a\\e\\071\\x3b\\$\\\\\\?caxyz", RegexOptions.None, "abcd\t\n\r\f\a\u001b9;$\\?caxyz", true); + yield return ("abcd\\t\\n\\r\\f\\a\\e\\071\\x3b\\$\\\\\\?caxyz", RegexOptions.None, "abcd\t\n\r\f\a\e9;$\\?caxyz", true); yield return ("a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz", RegexOptions.None, "abxyzpqrrrabbxyyyypqAzz", true); yield return ("a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz", RegexOptions.None, "aabxyzpqrrrabbxyyyypqAzz", true); yield return ("a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz", RegexOptions.None, "aaabxyzpqrrrabbxyyyypqAzz", true);