[Fixes #2862] asp-append-version now works with urls containing fragment

This commit is contained in:
Ajay Bhargav Baaskaran 2015-07-29 16:28:06 -07:00
parent 68c52adef4
commit 2792f10f9a
5 changed files with 15 additions and 7 deletions

View File

@ -49,10 +49,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
{ {
var resolvedPath = path; var resolvedPath = path;
var queryStringStartIndex = path.IndexOf('?'); var queryStringOrFragmentStartIndex = path.IndexOfAny(new char[] { '?', '#' });
if (queryStringStartIndex != -1) if (queryStringOrFragmentStartIndex != -1)
{ {
resolvedPath = path.Substring(0, queryStringStartIndex); resolvedPath = path.Substring(0, queryStringOrFragmentStartIndex);
} }
Uri uri; Uri uri;

View File

@ -26,6 +26,9 @@
<!-- Plain image tag with file version and path containing query string --> <!-- Plain image tag with file version and path containing query string -->
<img alt="Path with query string" src="/images/red.png?abc=def&amp;v=W2F5D366_nQ2fQqUk3URdgWy2ZekXjHzHJaY5yaiOOk" /> <img alt="Path with query string" src="/images/red.png?abc=def&amp;v=W2F5D366_nQ2fQqUk3URdgWy2ZekXjHzHJaY5yaiOOk" />
<!-- Plain image tag with file version and path containing fragment -->
<img alt="Path with query string" src="/images/red.png?v=W2F5D366_nQ2fQqUk3URdgWy2ZekXjHzHJaY5yaiOOk#abc" />
<!-- Plain image tag with file version and path linking to some action --> <!-- Plain image tag with file version and path linking to some action -->
<img alt="Path linking to some action" src="/controller/action" /> <img alt="Path linking to some action" src="/controller/action" />
</body> </body>

View File

@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
attributes: new TagHelperAttributeList attributes: new TagHelperAttributeList
{ {
{ "alt", new HtmlString("alt text") }, { "alt", new HtmlString("alt text") },
{ "data-extra", new HtmlString("something") }, { "data-extra", new HtmlString("something") },
{ "title", new HtmlString("Image title") }, { "title", new HtmlString("Image title") },
{ "src", "testimage.png" }, { "src", "testimage.png" },
{ "asp-append-version", "true" } { "asp-append-version", "true" }
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
attributes: new TagHelperAttributeList attributes: new TagHelperAttributeList
{ {
{ "alt", new HtmlString("alt text") }, { "alt", new HtmlString("alt text") },
{ "data-extra", new HtmlString("something") }, { "data-extra", new HtmlString("something") },
{ "title", new HtmlString("Image title") }, { "title", new HtmlString("Image title") },
}); });
@ -68,10 +68,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
// Act // Act
helper.Process(context, output); helper.Process(context, output);
// Assert // Assert
Assert.Equal(expectedOutput.TagName, output.TagName); Assert.Equal(expectedOutput.TagName, output.TagName);
Assert.Equal(4, output.Attributes.Count); Assert.Equal(4, output.Attributes.Count);
for(int i=0; i < expectedOutput.Attributes.Count; i++) for(int i=0; i < expectedOutput.Attributes.Count; i++)
{ {
var expectedAtribute = expectedOutput.Attributes[i]; var expectedAtribute = expectedOutput.Attributes[i];

View File

@ -23,6 +23,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
[InlineData("/hello/world", "/hello/world?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk")] [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=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", "/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) public void AddsVersionToFiles_WhenCacheIsAbsent(string filePath, string expected)
{ {
// Arrange // Arrange

View File

@ -28,6 +28,9 @@
<!-- Plain image tag with file version and path containing query string --> <!-- Plain image tag with file version and path containing query string -->
<img src="~/images/red.png?abc=def" alt="Path with query string" asp-append-version="true" /> <img src="~/images/red.png?abc=def" alt="Path with query string" asp-append-version="true" />
<!-- Plain image tag with file version and path containing fragment -->
<img src="~/images/red.png#abc" alt="Path with query string" asp-append-version="true" />
<!-- Plain image tag with file version and path linking to some action --> <!-- Plain image tag with file version and path linking to some action -->
<img src="/controller/action" alt="Path linking to some action" asp-append-version="true" /> <img src="/controller/action" alt="Path linking to some action" asp-append-version="true" />
</body> </body>