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:
@@ -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}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user