feat(branding): validate URL constants on module init (F11.2)

BrandingLinks (5 Hellion-owned URLs) and IntegrationLinks (2 third-party
plugin URLs) now run through UrlValidation.ValidateAll from a
[ModuleInitializer] hook. A malformed URL throws InvalidOperationException
at plugin load with the source class and the broken URL in the message,
instead of silently failing when a user clicks the button.

CA2255 is suppressed at the attribute sites — the warning is for library
code shipped to unknown consumers, but the plugin DLL is loaded directly
by Dalamud, which makes module-init the right one-shot hook.
This commit is contained in:
2026-05-12 17:48:51 +02:00
parent b9d3ff8f26
commit dd597fca44
3 changed files with 56 additions and 0 deletions
+21
View File
@@ -1,3 +1,6 @@
using System.Runtime.CompilerServices;
using HellionChat.Util;
namespace HellionChat.Branding; namespace HellionChat.Branding;
// Centralised — a future invite/URL rotation only touches this file. // Centralised — a future invite/URL rotation only touches this file.
@@ -9,4 +12,22 @@ internal static class BrandingLinks
"https://gitea.hellion-forge.cloud/JonKazama-Hellion/HellionChat"; "https://gitea.hellion-forge.cloud/JonKazama-Hellion/HellionChat";
public const string HellionForgeWebsite = "https://hellion-forge.cloud"; public const string HellionForgeWebsite = "https://hellion-forge.cloud";
public const string HellionMediaWebsite = "https://hellion-media.de/de"; public const string HellionMediaWebsite = "https://hellion-media.de/de";
// CA2255 warns against [ModuleInitializer] in library code, but Dalamud
// loads the plugin DLL directly so the module-init pass is the right hook
// for a one-shot URL sanity check at plugin load.
#pragma warning disable CA2255
[ModuleInitializer]
#pragma warning restore CA2255
internal static void ValidateUrls()
{
UrlValidation.ValidateAll(
nameof(BrandingLinks),
HellionForgeDiscordInvite,
HellionForgeGitea,
HellionChatRepo,
HellionForgeWebsite,
HellionMediaWebsite
);
}
} }
@@ -1,3 +1,6 @@
using System.Runtime.CompilerServices;
using HellionChat.Util;
namespace HellionChat.Integrations; namespace HellionChat.Integrations;
// Third-party plugin URLs — separate from BrandingLinks (Hellion-owned URLs). // Third-party plugin URLs — separate from BrandingLinks (Hellion-owned URLs).
@@ -5,4 +8,13 @@ internal static class IntegrationLinks
{ {
public const string HonorificRepo = "https://github.com/Caraxi/Honorific"; public const string HonorificRepo = "https://github.com/Caraxi/Honorific";
public const string HonorificAuthor = "https://github.com/Caraxi"; public const string HonorificAuthor = "https://github.com/Caraxi";
// See BrandingLinks.ValidateUrls for the CA2255 rationale.
#pragma warning disable CA2255
[ModuleInitializer]
#pragma warning restore CA2255
internal static void ValidateUrls()
{
UrlValidation.ValidateAll(nameof(IntegrationLinks), HonorificRepo, HonorificAuthor);
}
} }
+23
View File
@@ -0,0 +1,23 @@
namespace HellionChat.Util;
internal static class UrlValidation
{
// Used by BrandingLinks/IntegrationLinks at module init. A typo in a URL
// rotation throws loudly at plugin load instead of silently failing when
// a user clicks the broken button.
public static void ValidateAll(string source, params string[] urls)
{
foreach (var url in urls)
{
if (
!Uri.TryCreate(url, UriKind.Absolute, out var uri)
|| (uri.Scheme is not "https" and not "http")
)
{
throw new InvalidOperationException(
$"{source} contains malformed URL: {url}"
);
}
}
}
}