From 4f4b0cb3a80963aa3fd6f68938526df8447194a7 Mon Sep 17 00:00:00 2001 From: glax Date: Tue, 19 Sep 2023 19:22:49 +0200 Subject: [PATCH] LibraryConnector baseUrl regex --- Tranga/LibraryConnectors/LibraryConnector.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tranga/LibraryConnectors/LibraryConnector.cs b/Tranga/LibraryConnectors/LibraryConnector.cs index e3e3caa..cbf4446 100644 --- a/Tranga/LibraryConnectors/LibraryConnector.cs +++ b/Tranga/LibraryConnectors/LibraryConnector.cs @@ -1,5 +1,6 @@ using System.Net; using System.Net.Http.Headers; +using System.Text.RegularExpressions; using Logging; namespace Tranga.LibraryConnectors; @@ -20,7 +21,10 @@ public abstract class LibraryConnector : GlobalBase protected LibraryConnector(GlobalBase clone, string baseUrl, string auth, LibraryType libraryType) : base(clone) { - this.baseUrl = baseUrl; + Regex urlRex = new(@"https?:\/\/[0-9A-z\.]*"); + if (!urlRex.IsMatch(baseUrl)) + throw new ArgumentException("Base url does not match pattern"); + this.baseUrl = urlRex.Match(baseUrl).Value; this.auth = auth; this.libraryType = libraryType; }