From 3026a102d4e8c2e56e50e326920f8dafa5906625 Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Wed, 16 Oct 2024 11:27:11 +0900 Subject: [PATCH 1/2] Removed UTF8 BOM from output text file. --- RelaxVersioner.Core/Utilities.cs | 3 +++ RelaxVersioner.Core/Writers/NpmReplaceProvider.cs | 6 +++--- RelaxVersioner.Core/Writers/TextReplaceProvider.cs | 6 +++--- RelaxVersioner.Core/Writers/TextWriteProvider.cs | 2 +- RelaxVersioner/build/RelaxVersioner.props | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/RelaxVersioner.Core/Utilities.cs b/RelaxVersioner.Core/Utilities.cs index 2bfeb5a..d89162c 100644 --- a/RelaxVersioner.Core/Utilities.cs +++ b/RelaxVersioner.Core/Utilities.cs @@ -13,6 +13,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Text; using System.Threading.Tasks; using System.Xml.Linq; using GitReader; @@ -26,6 +27,8 @@ internal static class Utilities { private static readonly char[] directorySeparatorChar_ = { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }; + + public static readonly Encoding UTF8 = new UTF8Encoding(false); public static string GetDirectoryPath(string path) => Path.GetDirectoryName(path) switch diff --git a/RelaxVersioner.Core/Writers/NpmReplaceProvider.cs b/RelaxVersioner.Core/Writers/NpmReplaceProvider.cs index b98fad2..c5a98c9 100644 --- a/RelaxVersioner.Core/Writers/NpmReplaceProvider.cs +++ b/RelaxVersioner.Core/Writers/NpmReplaceProvider.cs @@ -93,9 +93,9 @@ void ReplaceSubKey(string key) stream => { using var tr = context.ReplaceInputPath is { } rip ? - new StreamReader(rip, Encoding.UTF8, true) : + new StreamReader(rip, Utilities.UTF8, true) : Console.In; - var tw = new StreamWriter(stream, Encoding.UTF8); + var tw = new StreamWriter(stream, Utilities.UTF8); Replace(tr, tw); }); @@ -108,7 +108,7 @@ void ReplaceSubKey(string key) } using var tr = context.ReplaceInputPath is { } rip ? - new StreamReader(rip, Encoding.UTF8, true) : + new StreamReader(rip, Utilities.UTF8, true) : Console.In; Replace(tr, Console.Out); } diff --git a/RelaxVersioner.Core/Writers/TextReplaceProvider.cs b/RelaxVersioner.Core/Writers/TextReplaceProvider.cs index d7b80b1..76835b9 100644 --- a/RelaxVersioner.Core/Writers/TextReplaceProvider.cs +++ b/RelaxVersioner.Core/Writers/TextReplaceProvider.cs @@ -63,9 +63,9 @@ void Replace(TextReader tr, TextWriter tw) stream => { using var tr = context.ReplaceInputPath is { } rip ? - new StreamReader(rip, Encoding.UTF8, true) : + new StreamReader(rip, Utilities.UTF8, true) : Console.In; - var tw = new StreamWriter(stream, Encoding.UTF8); + var tw = new StreamWriter(stream, Utilities.UTF8); Replace(tr, tw); }); @@ -78,7 +78,7 @@ void Replace(TextReader tr, TextWriter tw) } using var tr = context.ReplaceInputPath is { } rip ? - new StreamReader(rip, Encoding.UTF8, true) : + new StreamReader(rip, Utilities.UTF8, true) : Console.In; Replace(tr, Console.Out); } diff --git a/RelaxVersioner.Core/Writers/TextWriteProvider.cs b/RelaxVersioner.Core/Writers/TextWriteProvider.cs index f4d4af4..23b799d 100644 --- a/RelaxVersioner.Core/Writers/TextWriteProvider.cs +++ b/RelaxVersioner.Core/Writers/TextWriteProvider.cs @@ -60,7 +60,7 @@ void Write(TextWriter tw, bool emitEol) Processor.WriteSafeTransacted( context.OutputPath, - stream => Write(new StreamWriter(stream, Encoding.UTF8), false)); + stream => Write(new StreamWriter(stream, Utilities.UTF8), false)); } else { diff --git a/RelaxVersioner/build/RelaxVersioner.props b/RelaxVersioner/build/RelaxVersioner.props index 6f6f9ac..6bd3cb5 100644 --- a/RelaxVersioner/build/RelaxVersioner.props +++ b/RelaxVersioner/build/RelaxVersioner.props @@ -82,7 +82,7 @@ string path = Path.GetFullPath(File.ItemSpec); using (Stream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { - TextWriter tw = new StreamWriter(fs, Encoding.UTF8); + TextWriter tw = new StreamWriter(fs, new UTF8Encoding(false)); string text = Text; if (text != null) { From abb8db375a4012457cf54890a3c24d2a60132e72 Mon Sep 17 00:00:00 2001 From: Kouji Matsui Date: Wed, 16 Oct 2024 11:29:00 +0900 Subject: [PATCH 2/2] Updated readme. --- README.ja.md | 2 ++ README.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.ja.md b/README.ja.md index f3d1c54..7506183 100644 --- a/README.ja.md +++ b/README.ja.md @@ -545,6 +545,8 @@ nuspecファイルを使ってパッケージを生成する場合は、デフ ## 履歴 +* 3.9.0: + * UTF8テキストファイル出力をBOMなしに変更。 * 3.8.0: * NPM `package.json` のバージョンを自動挿入する、NPMモードを追加。 * NuGetパッケージをビルドする時に、ビルドログにバージョン番号のゴミが出力されていたのを修正。 diff --git a/README.md b/README.md index 5b657a4..58c5a4b 100644 --- a/README.md +++ b/README.md @@ -526,6 +526,8 @@ When you are using a nuspec file to generate a NuGet package, there are addition ## History +* 3.9.0: + * Changed UTF8 text file output to no BOM. * 3.8.0: * Added NPM mode, which automatically inserts the version of NPM `package.json`. * Fixed version number print garbage in the build log when building NuGet packages.