From 0e04f3b68b0c3108deb11ff1edd823423ddbe4a7 Mon Sep 17 00:00:00 2001 From: Scott Lerch Date: Tue, 14 Jul 2026 12:02:51 -0700 Subject: [PATCH] #131 Add the missing InvalidHostnames key to Core's Resources.resx The strongly-typed Resources.InvalidHostnames getter existed but Core's Resources.resx had no matching entry, so it resolved to null. HostsEntry.ValidateHostnames does `SetError(nameof(HostNames), !_hostnamesValid ? Resources.InvalidHostnames : null)` and SetError treats null as "clear the error", so an invalid hostname surfaced a BLANK IDataErrorInfo message in both the classic and modern editions instead of "Invalid host names". Add the key ("Invalid host names", matching the WinForm resource) plus a regression test asserting the invalid-hostname error message is the non-empty resource string. Split out of the larger CI/coverage PR #132 so the user-facing fix can land on its own. Closes #131 Co-Authored-By: Claude Opus 4.8 --- HostsFileEditor.Core.Tests/HostsEntryTests.cs | 14 ++++++++++++++ HostsFileEditor.Core/Properties/Resources.resx | 3 +++ 2 files changed, 17 insertions(+) diff --git a/HostsFileEditor.Core.Tests/HostsEntryTests.cs b/HostsFileEditor.Core.Tests/HostsEntryTests.cs index 9aaf604..d52cc67 100644 --- a/HostsFileEditor.Core.Tests/HostsEntryTests.cs +++ b/HostsFileEditor.Core.Tests/HostsEntryTests.cs @@ -81,6 +81,20 @@ public void Invalid_Hostname_AfterEdit() entry.Valid.ShouldBeFalse(); } + // Regression for #131: Resources.InvalidHostnames had no matching key in Core's Resources.resx, + // so it resolved to null and SetError(null) cleared the error — an invalid hostname surfaced a + // BLANK IDataErrorInfo message (rather than "Invalid host names") in both editions. + [TestMethod] + public void Invalid_Hostname_HasNonBlankErrorMessage() + { + var entry = new HostsEntry("127.0.0.1 goodhost"); + entry.HostNames = "bad@host"; // invalid character + + entry.Valid.ShouldBeFalse(); + entry["HostNames"].ShouldNotBeNullOrEmpty(); + entry["HostNames"].ShouldBe(HostsFileEditor.Properties.Resources.InvalidHostnames); + } + [TestMethod] public void ToString_ReturnsExpected() { diff --git a/HostsFileEditor.Core/Properties/Resources.resx b/HostsFileEditor.Core/Properties/Resources.resx index 039c016..d5114da 100644 --- a/HostsFileEditor.Core/Properties/Resources.resx +++ b/HostsFileEditor.Core/Properties/Resources.resx @@ -68,6 +68,9 @@ Invalid Host Entries + + Invalid host names + Hosts File Editor Question