diff --git a/src/Geta.NotFoundHandler/Core/Redirects/CustomRedirectCollection.cs b/src/Geta.NotFoundHandler/Core/Redirects/CustomRedirectCollection.cs index c1f84c5a..adff85fe 100644 --- a/src/Geta.NotFoundHandler/Core/Redirects/CustomRedirectCollection.cs +++ b/src/Geta.NotFoundHandler/Core/Redirects/CustomRedirectCollection.cs @@ -222,7 +222,7 @@ private static void BuildPath( builder.Append(path); - if (hasAppendSegment && !pathHasTrailingSlash) + if (hasAppendSegment && !path.EndsWith("/")) { builder.Append('/'); } diff --git a/tests/Geta.NotFoundHandler.Tests/CustomRedirectCollectionTests.cs b/tests/Geta.NotFoundHandler.Tests/CustomRedirectCollectionTests.cs index 5e52ba0f..9071569d 100644 --- a/tests/Geta.NotFoundHandler.Tests/CustomRedirectCollectionTests.cs +++ b/tests/Geta.NotFoundHandler.Tests/CustomRedirectCollectionTests.cs @@ -399,5 +399,24 @@ public void Find_decodes_plus_sign_correctly() Assert.Equal(expected, actual.NewUrl); } + + /// + /// https://github.com/Geta/geta-notfoundhandler/issues/137 + /// + [Fact] + public void Find_does_add_slash_when_new_url_is_missing_trailing_slash() + { + var collection = new CustomRedirectCollection + { + new CustomRedirect("/content", "/legacy"), + }; + + var urlToFind = "/content/file/"; + var expected = "/legacy/file/"; + + var actual = collection.Find(urlToFind.ToUri()); + + Assert.Equal(expected, actual.NewUrl); + } } }