diff --git a/src/Microsoft.Owin/PathString.cs b/src/Microsoft.Owin/PathString.cs index 67b0d46a..4a213b5d 100644 --- a/src/Microsoft.Owin/PathString.cs +++ b/src/Microsoft.Owin/PathString.cs @@ -81,8 +81,7 @@ public string ToUriComponent() while (i < _value.Length) { - var isPercentEncodedChar = PathStringHelper.IsPercentEncodedChar(_value, i); - if (PathStringHelper.IsValidPathChar(_value[i]) || isPercentEncodedChar) + if (PathStringHelper.IsValidPathChar(_value[i])) { if (requiresEscaping) { @@ -99,16 +98,8 @@ public string ToUriComponent() count = 0; } - if (isPercentEncodedChar) - { - count += 3; - i += 3; - } - else - { - count++; - i++; - } + count++; + i++; } else { diff --git a/tests/Microsoft.Owin.Tests/PathStringTests.cs b/tests/Microsoft.Owin.Tests/PathStringTests.cs index bf660876..da7fc509 100644 --- a/tests/Microsoft.Owin.Tests/PathStringTests.cs +++ b/tests/Microsoft.Owin.Tests/PathStringTests.cs @@ -170,11 +170,11 @@ public void EscapingIsCorrectWhenUserDefinedPathHasValueWhichHappensToBeAnEscape singleEscapedPath.Value.ShouldBe("/one%2Ftwo"); var doubleEscapedString = singleEscapedPath.ToUriComponent(); - doubleEscapedString.ShouldBe("/one%2Ftwo"); + doubleEscapedString.ShouldBe("/one%252Ftwo"); var recreatedPath = PathString.FromUriComponent(doubleEscapedString); - recreatedPath.Value.ShouldBe("/one/two"); - recreatedPath.ToUriComponent().ShouldBe("/one/two"); + recreatedPath.Value.ShouldBe("/one%2Ftwo"); + recreatedPath.ToUriComponent().ShouldBe("/one%252Ftwo"); } [Theory] diff --git a/tests/Microsoft.Owin.Tests/UriTests.cs b/tests/Microsoft.Owin.Tests/UriTests.cs index 68194bf9..6e278a2f 100644 --- a/tests/Microsoft.Owin.Tests/UriTests.cs +++ b/tests/Microsoft.Owin.Tests/UriTests.cs @@ -23,7 +23,7 @@ public class UriTests [InlineData("/a%.+#?", "/z", "a#b", "http://host:1/a%25.+%23%3F/z?a%23b")] // Note: Http.Sys will not accept any characters in the path that it cannot un-escape, // so this double escaping is not a problem in production. - [InlineData("", "/%20", "%20", "http://host:1/%20?%20")] + [InlineData("", "/%20", "%20", "http://host:1/%2520?%20")] public void UriReconstruction(string pathBase, string path, string query, string expected) { IOwinRequest request = CreateRequest(pathBase, path, query);