From fa65a644eb116625b29c35803bec7fc19d850cb7 Mon Sep 17 00:00:00 2001 From: rlittlesii <6969701+RLittlesII@users.noreply.github.com> Date: Wed, 8 May 2024 16:44:08 -0600 Subject: [PATCH] verifying GetSegmentName --- src/Prism.Core/Common/UriParsingHelper.cs | 11 +++++++++-- .../Fixtures/Common/UriParsingHelperFixture.cs | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Prism.Core/Common/UriParsingHelper.cs b/src/Prism.Core/Common/UriParsingHelper.cs index 8e9acb165..3f3ad1db8 100644 --- a/src/Prism.Core/Common/UriParsingHelper.cs +++ b/src/Prism.Core/Common/UriParsingHelper.cs @@ -72,7 +72,7 @@ public static INavigationParameters GetSegmentParameters(string uriSegment, INav { var navParameters = GetSegmentParameters(uriSegment); - if (parameters != null) + if (parameters is not null) { foreach (KeyValuePair navigationParameter in parameters) { @@ -154,7 +154,14 @@ public static INavigationParameters ParseQuery(Uri uri) /// A uri string. /// A . /// Throws an when the string is null or empty. - public static Uri Parse(string uri) => uri.StartsWith("/", StringComparison.Ordinal) ? new Uri("http://localhost" + uri, UriKind.Absolute) : new Uri(uri, UriKind.RelativeOrAbsolute); + public static Uri Parse(string uri) + { + ArgumentNullException.ThrowIfNull(uri); + + return uri.StartsWith("/", StringComparison.Ordinal) + ? new Uri("http://localhost" + uri, UriKind.Absolute) + : new Uri(uri, UriKind.RelativeOrAbsolute); + } /// /// This will provide the existing if it is already Absolute, otherwise diff --git a/tests/Maui/Prism.Maui.Tests/Fixtures/Common/UriParsingHelperFixture.cs b/tests/Maui/Prism.Maui.Tests/Fixtures/Common/UriParsingHelperFixture.cs index ef509897f..2327ac37f 100644 --- a/tests/Maui/Prism.Maui.Tests/Fixtures/Common/UriParsingHelperFixture.cs +++ b/tests/Maui/Prism.Maui.Tests/Fixtures/Common/UriParsingHelperFixture.cs @@ -92,6 +92,13 @@ public void ParametersParsedFromNavigationParametersInAbsoluteUri() Assert.Equal("dan", parameters["name"]); } + [Fact] + public void TargetNameParsedFromEmptySegment() + { + var target = UriParsingHelper.GetSegmentName(string.Empty); + Assert.Equal(string.Empty, target); + } + [Fact] public void TargetNameParsedFromSingleSegment() {