From f8704e425b8cbf16c03974760bfffb8614fe8340 Mon Sep 17 00:00:00 2001 From: MattMo Date: Thu, 2 Feb 2023 16:14:32 -0800 Subject: [PATCH] Route arguments are now automatically url decoded by the RouteMatcher. Added a unit test to cover this case. Bumped package version to 1.1.8 --- Rest.Net.Tests/RouteMatcherTests.cs | 8 ++++++++ Rest.Net/Rest.Net.csproj | 2 +- Rest.Net/RouteMatcher.cs | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Rest.Net.Tests/RouteMatcherTests.cs b/Rest.Net.Tests/RouteMatcherTests.cs index 8b36a2d..caf91e4 100644 --- a/Rest.Net.Tests/RouteMatcherTests.cs +++ b/Rest.Net.Tests/RouteMatcherTests.cs @@ -69,6 +69,14 @@ namespace MontoyaTech.Rest.Net.Tests arguments[1].Should().Be("2"); } + [Fact] + public void SyntaxWithArgumentsUrlEncodedShouldDecode() + { + RouteMatcher.Matches("http://localhost/a/b%20c", "/a/{name}", out string[] arguments).Should().BeTrue(); + arguments.Length.Should().Be(1); + arguments[0].Should().Be("b c"); + } + [Fact] public void SyntaxWithWildcardShouldMatch() { diff --git a/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net.csproj index aefd13a..34bfb69 100644 --- a/Rest.Net/Rest.Net.csproj +++ b/Rest.Net/Rest.Net.csproj @@ -17,7 +17,7 @@ MontoyaTech.Rest.Net MontoyaTech.Rest.Net True - 1.1.7 + 1.1.8 Logo_Symbol_Black_Outline.png diff --git a/Rest.Net/RouteMatcher.cs b/Rest.Net/RouteMatcher.cs index 559ebd1..9f5ab98 100644 --- a/Rest.Net/RouteMatcher.cs +++ b/Rest.Net/RouteMatcher.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Net; namespace MontoyaTech.Rest.Net { @@ -121,7 +122,7 @@ namespace MontoyaTech.Rest.Net } else if (condition.StartsWith("{") && condition.EndsWith("}")) { - arguments[argumentIndex++] = urlSegment; + arguments[argumentIndex++] = WebUtility.UrlDecode(urlSegment); match = true; }