diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 543c050405..86d27eaf97 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591;CS0649;xUnit1026;xUnit1013;msb3277;CS0436 - 17.1.3 + 17.1.4 enable 10 true diff --git a/src/Verify/IoHelpers.cs b/src/Verify/IoHelpers.cs index 4541e8c56d..61bb35b2d4 100644 --- a/src/Verify/IoHelpers.cs +++ b/src/Verify/IoHelpers.cs @@ -2,8 +2,6 @@ { static readonly UTF8Encoding Utf8 = new(true, true); - static readonly string UTF8Preamble = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()); - public static void DeleteIfEmpty(string path) { var info = new FileInfo(path); @@ -45,19 +43,9 @@ static async Task ReadStringWithFixedLines(this Stream stream) return builder.ToString(); } - static string TrimPreamble(string text) - { - if (text.StartsWith(UTF8Preamble)) - { - return text.Substring(UTF8Preamble.Length); - } - - return text; - } - #if NETSTANDARD2_1 || NET5_0_OR_GREATER public static Task WriteText(string path, string text) => - File.WriteAllTextAsync(path, TrimPreamble(text), Utf8); + File.WriteAllTextAsync(path, text, Utf8); public static async Task ReadStringWithFixedLines(string path) { @@ -80,7 +68,7 @@ public static async Task WriteStream(string path, Stream stream) #else public static async Task WriteText(string path, string text) { - var encodedText = Utf8.GetBytes(TrimPreamble(text)); + var encodedText = Utf8.GetBytes(text); using var stream = OpenWrite(path); await stream.WriteAsync(encodedText, 0, encodedText.Length); diff --git a/src/Verify/Verifier/InnerVerifier_Inner.cs b/src/Verify/Verifier/InnerVerifier_Inner.cs index a2331e9fe0..36d7f37a7e 100644 --- a/src/Verify/Verifier/InnerVerifier_Inner.cs +++ b/src/Verify/Verifier/InnerVerifier_Inner.cs @@ -58,12 +58,17 @@ bool TryGetTargetBuilder(object? target, [NotNullWhen(true)] out StringBuilder? return true; } - if (!hasAppends && target is string stringTarget) + if (target is string stringTarget) { - builder = new(stringTarget); - builder.FixNewlines(); - extension = settings.ExtensionOrTxt(); - return true; + target = stringTarget = TrimPreamble(stringTarget); + + if (!hasAppends) + { + builder = new(stringTarget); + builder.FixNewlines(); + extension = settings.ExtensionOrTxt(); + return true; + } } extension = "txt"; @@ -77,4 +82,7 @@ bool TryGetTargetBuilder(object? target, [NotNullWhen(true)] out StringBuilder? return true; } + + static string TrimPreamble(string text) => + text.TrimStart('\uFEFF'); } \ No newline at end of file