From a8f0fd48dbed03cda9a2a967176f1fb811b9ef28 Mon Sep 17 00:00:00 2001 From: "Martin Hinshelwood nkdAgility.com" Date: Mon, 23 Sep 2024 16:25:23 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20(TfsEndpointOptions.cs):=20i?= =?UTF-8?q?mprove=20URL=20validation=20logic=20for=20Collection=20property?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous implementation used `Uri.IsWellFormedUriString` which is less robust. The new implementation uses `Uri.TryCreate` to ensure the Collection property is a valid URL, providing more accurate validation and error handling. This change enhances the reliability of the URL validation process. --- .../Endpoints/TfsEndpointOptions.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/MigrationTools.Clients.TfsObjectModel/Endpoints/TfsEndpointOptions.cs b/src/MigrationTools.Clients.TfsObjectModel/Endpoints/TfsEndpointOptions.cs index 0f36e7dc0..717a9a95b 100644 --- a/src/MigrationTools.Clients.TfsObjectModel/Endpoints/TfsEndpointOptions.cs +++ b/src/MigrationTools.Clients.TfsObjectModel/Endpoints/TfsEndpointOptions.cs @@ -42,9 +42,14 @@ public ValidateOptionsResult Validate(string name, TfsEndpointOptions options) { errors.Add("The Collection property must not be null."); } - else if (!Uri.IsWellFormedUriString(options.Collection.ToString(), UriKind.Absolute)) + else { - errors.Add("The Collection property must be a valid URL."); + Uri output; + if (!Uri.TryCreate(options.Collection.ToString(), UriKind.Absolute, out output)) + { + errors.Add("The Collection property must be a valid URL."); + } + } // Validate Project - Must not be null or empty @@ -66,7 +71,7 @@ public ValidateOptionsResult Validate(string name, TfsEndpointOptions options) } else { - ValidateOptionsResult lmr= options.LanguageMaps.Validate(name, options.LanguageMaps); + ValidateOptionsResult lmr = options.LanguageMaps.Validate(name, options.LanguageMaps); if (lmr != ValidateOptionsResult.Success) { errors.AddRange(lmr.Failures); From 43559bbd1bb75b59b1796f7447c22f640f9c4855 Mon Sep 17 00:00:00 2001 From: "Martin Hinshelwood nkdAgility.com" Date: Mon, 23 Sep 2024 16:30:17 +0100 Subject: [PATCH 2/2] Add Uri.UnescapeDataString(options.Collection.ToString()) --- .../Endpoints/TfsEndpointOptions.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/MigrationTools.Clients.TfsObjectModel/Endpoints/TfsEndpointOptions.cs b/src/MigrationTools.Clients.TfsObjectModel/Endpoints/TfsEndpointOptions.cs index 717a9a95b..ebe2556fc 100644 --- a/src/MigrationTools.Clients.TfsObjectModel/Endpoints/TfsEndpointOptions.cs +++ b/src/MigrationTools.Clients.TfsObjectModel/Endpoints/TfsEndpointOptions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Text.Encodings.Web; using Microsoft.Extensions.Options; using MigrationTools.Endpoints.Infrastructure; using Newtonsoft.Json; @@ -44,8 +45,8 @@ public ValidateOptionsResult Validate(string name, TfsEndpointOptions options) } else { - Uri output; - if (!Uri.TryCreate(options.Collection.ToString(), UriKind.Absolute, out output)) + Uri output; + if (!Uri.TryCreate(Uri.UnescapeDataString(options.Collection.ToString()), UriKind.Absolute, out output)) { errors.Add("The Collection property must be a valid URL."); }