Repository: dotnet/runtime
File: src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.EscapeUnescape.Tests.cs (C#)

Code before:
        [InlineData("Z", "Z")]
        [InlineData("0", "0")]
        [InlineData("9", "9")]
        [InlineData("-", "-")]
        [InlineData("_", "_")]
        [InlineData(":", ":")]
        [InlineData(";", ";")]
        [InlineData("<", "<")]
        [InlineData(">", ">")]
        [InlineData("=", "=")]
        [InlineData("@", "@")]
        [InlineData("!", "!")]
        [InlineData("~", "~")]
        [InlineData("`", "`")]
        [InlineData("'", "'")]
        [InlineData("\"", "\"")]
        [InlineData(",", ",")]
        [InlineData("/", "/")]
        [InlineData("}", "}")]
        [InlineData("]", "]")]
        [InlineData("%", "%")]
        [InlineData("&", "&")]
        public static void Escape_CharactersThatShouldNotBeEscaped(string str, string expected)
        {
            Assert.Equal(expected, Regex.Escape(str));
        }

        /// <summary>
        /// Tests escape with mixed content containing metacharacters and regular characters.
        /// </summary>
        [Theory]
        [InlineData("a.b", @"a\.b")]
        [InlineData("hello world", @"hello\ world")]
        [InlineData("a*b+c", @"a\*b\+c")]
        [InlineData("(abc)", @"\(abc\)")]
        [InlineData("[abc]", @"\[abc]")]
        [InlineData("{1,2}", @"\{1,2}")]
        [InlineData("a\tb\nc", @"a\tb\nc")]
        [InlineData("a\vb", "a\vb")] // vertical tab should NOT be escaped
        public static void Escape_MixedContent(string str, string expected)
        {
            Assert.Equal(expected, Regex.Escape(str));
        }

        [Theory]
        [InlineData("Hello", "Hello")]
        [InlineData(@"\#\$\^\*\+\(\)\{}<>\\\|\.\ ", "#$^*+(){}<>\\|. ")]
        [InlineData("\\n\\r\\t\\f", "\n\r\t\f")]
        [InlineData(@"\\", @"\")]
        [InlineData(@"\", "")]
        [InlineData("", "")]

Review comment (security):
```suggestion
        [Theory]
        [InlineData("\v")] // vertical tab should NOT be escaped
        [InlineData("a")]
        [InlineData("Z")]
        [InlineData("0")]
        [InlineData("9")]
        [InlineData("-")]
        [InlineData("_")]
        [InlineData(":")]
        [InlineData(";")]
        [InlineData("<")]
        [InlineData(">")]
        [InlineData("=")]
        [InlineData("@")]
        [InlineData("!")]
        [InlineData("~")]
        [InlineData("`")]
        [InlineData("'")]
        [InlineData("\"")]
        [InlineData(",")]
        [InlineData("/")]
        [InlineData("}")]
        [InlineData("]")]
        [InlineData("%")]
        [InlineData("&")]
        public static void Escape_CharactersThatShouldNotBeEscaped(string str)
        {
            Assert.Equal(str, Regex.Escape(str));
        }
```

Code after:
        [InlineData("Z")]
        [InlineData("0")]
        [InlineData("9")]
        [InlineData("-")]
        [InlineData("_")]
        [InlineData(":")]
        [InlineData(";")]
        [InlineData("<")]
        [InlineData(">")]
        [InlineData("=")]
        [InlineData("@")]
        [InlineData("!")]
        [InlineData("~")]
        [InlineData("`")]
        [InlineData("'")]
        [InlineData("\"")]
        [InlineData(",")]
        [InlineData("/")]
        [InlineData("}")]
        [InlineData("]")]
        [InlineData("%")]
        [InlineData("&")]
        public static void Escape_CharactersThatShouldNotBeEscaped(string str)
        {
            Assert.Equal(str, Regex.Escape(str));
        }

        /// <summary>
        /// Tests escape with mixed content containing metacharacters and regular characters.
        /// </summary>
        [Theory]
        [InlineData("a.b", @"a\.b")]
        [InlineData("hello world", @"hello\ world")]
        [InlineData("a*b+c", @"a\*b\+c")]
        [InlineData("(abc)", @"\(abc\)")]
        [InlineData("[abc]", @"\[abc]")]
        [InlineData("{1,2}", @"\{1,2}")]
        [InlineData("a\tb\nc", @"a\tb\nc")]
        [InlineData("a\vb", "a\vb")] // vertical tab should NOT be escaped
        public static void Escape_MixedContent(string str, string expected)
        {
            Assert.Equal(expected, Regex.Escape(str));
        }

        [Theory]
        [InlineData("Hello", "Hello")]
        [InlineData(@"\#\$\^\*\+\(\)\{}<>\\\|\.\ ", "#$^*+(){}<>\\|. ")]
        [InlineData("\\n\\r\\t\\f", "\n\r\t\f")]
        [InlineData(@"\\", @"\")]
        [InlineData(@"\", "")]
        [InlineData("", "")]