From 4515181f2e3667cb2bb1d3ee5091588ce0b70ac8 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Fri, 30 Oct 2026 19:28:17 -0600 Subject: [PATCH] Test that a hand-edited Windows install ID file is kept as is The README invites putting one's own value in the install ID file. A file saved by Notepad has CRLF line endings and may carry a UTF-8 byte order mark or be UTF-16; the ID in it must be read and the file left untouched. Co-Authored-By: Claude Opus 5.5 --- tests/TraceClient.Tests/InstallIdTest.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/TraceClient.Tests/InstallIdTest.cs b/tests/TraceClient.Tests/InstallIdTest.cs index 118f462..f495474 100644 --- a/tests/TraceClient.Tests/InstallIdTest.cs +++ b/tests/TraceClient.Tests/InstallIdTest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using System.Threading; using Xunit; @@ -84,6 +85,28 @@ public void InstallIdFromFile_KeepsALineExactlyAtTheLimit() Assert.Equal(atTheLimit + "\n", File.ReadAllText(path)); // not replaced } + [Theory] + [InlineData("utf-8")] + [InlineData("utf-8-bom")] + [InlineData("utf-16")] + public void InstallIdFromFile_KeepsAHandEditedWindowsFileAsIs(string encoding) + { + // "Put your own value in it": a file saved by Notepad has CRLF line + // endings and may start with a byte order mark, or be UTF-16 outright. + Directory.CreateDirectory(_directory); + string path = Path.Combine(_directory, "install-id"); + Encoding chosen = encoding == "utf-8" ? new UTF8Encoding(false) + : encoding == "utf-8-bom" ? new UTF8Encoding(true) + : Encoding.Unicode; + File.WriteAllText(path, "my-own-id \r\nsecond\r\n", chosen); + byte[] before = File.ReadAllBytes(path); + + string id = TraceClient.InstallIdFromFile(path); + + Assert.Equal("my-own-id", id); + Assert.Equal(before, File.ReadAllBytes(path)); // not replaced + } + [Fact] public void InstallIdFromFile_FallsBackToAnInMemoryIdWithoutThrowing() {