From 2792f10f9ab71e6476e11b499cb0eed1922716a8 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Wed, 29 Jul 2015 16:28:06 -0700 Subject: [PATCH] [Fixes #2862] asp-append-version now works with urls containing fragment --- .../Internal/FileVersionProvider.cs | 6 +++--- .../HtmlGenerationWebSite.HtmlGeneration_Home.Image.html | 3 +++ .../ImageTagHelperTest.cs | 8 ++++---- .../Internal/FileVersionProviderTest.cs | 2 ++ .../Views/HtmlGeneration_Home/Image.cshtml | 3 +++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs index b8bad61709..a103cb5876 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs @@ -49,10 +49,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal { var resolvedPath = path; - var queryStringStartIndex = path.IndexOf('?'); - if (queryStringStartIndex != -1) + var queryStringOrFragmentStartIndex = path.IndexOfAny(new char[] { '?', '#' }); + if (queryStringOrFragmentStartIndex != -1) { - resolvedPath = path.Substring(0, queryStringStartIndex); + resolvedPath = path.Substring(0, queryStringOrFragmentStartIndex); } Uri uri; diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Image.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Image.html index a102c65158..1a429f0103 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Image.html +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Image.html @@ -26,6 +26,9 @@ Path with query string + + Path with query string + Path linking to some action diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ImageTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ImageTagHelperTest.cs index bc6425ef57..9d1c298940 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ImageTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ImageTagHelperTest.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers attributes: new TagHelperAttributeList { { "alt", new HtmlString("alt text") }, - { "data-extra", new HtmlString("something") }, + { "data-extra", new HtmlString("something") }, { "title", new HtmlString("Image title") }, { "src", "testimage.png" }, { "asp-append-version", "true" } @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers attributes: new TagHelperAttributeList { { "alt", new HtmlString("alt text") }, - { "data-extra", new HtmlString("something") }, + { "data-extra", new HtmlString("something") }, { "title", new HtmlString("Image title") }, }); @@ -68,10 +68,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Act helper.Process(context, output); - // Assert + // Assert Assert.Equal(expectedOutput.TagName, output.TagName); Assert.Equal(4, output.Attributes.Count); - + for(int i=0; i < expectedOutput.Attributes.Count; i++) { var expectedAtribute = expectedOutput.Attributes[i]; diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/FileVersionProviderTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/FileVersionProviderTest.cs index 85aa606f18..06a591446b 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/FileVersionProviderTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/FileVersionProviderTest.cs @@ -23,6 +23,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal [InlineData("/hello/world", "/hello/world?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk")] [InlineData("/hello/world?q=test", "/hello/world?q=test&v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk")] [InlineData("/hello/world?q=foo&bar", "/hello/world?q=foo&bar&v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk")] + [InlineData("/hello/world?q=foo&bar#abc", "/hello/world?q=foo&bar&v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk#abc")] + [InlineData("/hello/world#somefragment", "/hello/world?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk#somefragment")] public void AddsVersionToFiles_WhenCacheIsAbsent(string filePath, string expected) { // Arrange diff --git a/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Image.cshtml b/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Image.cshtml index 95f9ec3873..7af8b7eec5 100644 --- a/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Image.cshtml +++ b/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Image.cshtml @@ -28,6 +28,9 @@ Path with query string + + Path with query string + Path linking to some action