From e200bad9e537be4fe52ba9c2b42b754276286a72 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Sat, 13 Jul 2019 14:09:50 -0500 Subject: [PATCH] catch if URL is improperly formatted --- src/FilterLists.Agent/Infrastructure/Web/UrlValidator.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/FilterLists.Agent/Infrastructure/Web/UrlValidator.cs b/src/FilterLists.Agent/Infrastructure/Web/UrlValidator.cs index 15af62157..99bdbf6e5 100644 --- a/src/FilterLists.Agent/Infrastructure/Web/UrlValidator.cs +++ b/src/FilterLists.Agent/Infrastructure/Web/UrlValidator.cs @@ -27,6 +27,14 @@ public UrlValidator(HttpClient httpClient, ILogger logger) public async Task ValidateAsync(EntityUrl entityUrl, CancellationToken cancellationToken) { var url = entityUrl.Url; + if (!Uri.IsWellFormedUriString(url.OriginalString, UriKind.Absolute)) + { + entityUrl.SetBroken(); + _logger.LogError( + $"Url validation for ({url.OriginalString}) failed because it appears to be improperly formatted."); + return entityUrl; + } + try { using var response =