[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 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;

View File

@ -26,6 +26,9 @@
<!-- 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" />
<!-- 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 -->
<img alt="Path linking to some action" src="/controller/action" />
</body>

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?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

View File

@ -28,6 +28,9 @@
<!-- 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" />
<!-- 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 -->
<img src="/controller/action" alt="Path linking to some action" asp-append-version="true" />
</body>