diff --git a/Tranga/GlobalBase.cs b/Tranga/GlobalBase.cs index 34b3cd7..89e66f0 100644 --- a/Tranga/GlobalBase.cs +++ b/Tranga/GlobalBase.cs @@ -1,4 +1,5 @@ using System.Globalization; +using System.Text.RegularExpressions; using Logging; using Newtonsoft.Json; using Tranga.LibraryConnectors; @@ -14,6 +15,7 @@ public abstract class GlobalBase protected HashSet libraryConnectors { get; init; } protected List cachedPublications { get; init; } protected static readonly NumberFormatInfo numberFormatDecimalPoint = new (){ NumberDecimalSeparator = "." }; + protected static readonly Regex baseUrlRex = new(@"https?:\/\/[0-9A-z\.]*"); protected GlobalBase(GlobalBase clone) { diff --git a/Tranga/LibraryConnectors/LibraryConnector.cs b/Tranga/LibraryConnectors/LibraryConnector.cs index 5da0131..64ba213 100644 --- a/Tranga/LibraryConnectors/LibraryConnector.cs +++ b/Tranga/LibraryConnectors/LibraryConnector.cs @@ -22,10 +22,9 @@ public abstract class LibraryConnector : GlobalBase protected LibraryConnector(GlobalBase clone, string baseUrl, string auth, LibraryType libraryType) : base(clone) { Log($"Creating libraryConnector {Enum.GetName(libraryType)}"); - Regex urlRex = new(@"https?:\/\/[0-9A-z\.]*"); - if (!urlRex.IsMatch(baseUrl)) + if (!baseUrlRex.IsMatch(baseUrl)) throw new ArgumentException("Base url does not match pattern"); - this.baseUrl = urlRex.Match(baseUrl).Value; + this.baseUrl = baseUrlRex.Match(baseUrl).Value; this.auth = auth; this.libraryType = libraryType; } diff --git a/Tranga/NotificationConnectors/Gotify.cs b/Tranga/NotificationConnectors/Gotify.cs index deb8b57..cbe3d9c 100644 --- a/Tranga/NotificationConnectors/Gotify.cs +++ b/Tranga/NotificationConnectors/Gotify.cs @@ -13,7 +13,9 @@ public class Gotify : NotificationConnector [JsonConstructor] public Gotify(GlobalBase clone, string endpoint, string appToken) : base(clone, NotificationConnectorType.Gotify) { - this.endpoint = endpoint; + if (!baseUrlRex.IsMatch(endpoint)) + throw new ArgumentException("endpoint does not match pattern"); + this.endpoint = baseUrlRex.Match(endpoint).Value;; this.appToken = appToken; }