Fixes for FileVersionProvider
- Path with query string works - No exception is thrown for absolute path
This commit is contained in:
parent
4d5604690d
commit
6213354b85
|
|
@ -48,6 +48,20 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
|
||||||
public string AddFileVersionToPath([NotNull] string path)
|
public string AddFileVersionToPath([NotNull] string path)
|
||||||
{
|
{
|
||||||
var resolvedPath = path;
|
var resolvedPath = path;
|
||||||
|
|
||||||
|
var queryStringStartIndex = path.IndexOf('?');
|
||||||
|
if (queryStringStartIndex != -1)
|
||||||
|
{
|
||||||
|
resolvedPath = path.Substring(0, queryStringStartIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
Uri uri;
|
||||||
|
if (Uri.TryCreate(resolvedPath, UriKind.Absolute, out uri))
|
||||||
|
{
|
||||||
|
// Don't append version if the path is absolute.
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
var fileInfo = _fileProvider.GetFileInfo(resolvedPath);
|
var fileInfo = _fileProvider.GetFileInfo(resolvedPath);
|
||||||
if (!fileInfo.Exists)
|
if (!fileInfo.Exists)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,22 @@
|
||||||
<!-- Plain image tag -->
|
<!-- Plain image tag -->
|
||||||
<img src="/images/red.png" alt="Red block" title="<the title>">
|
<img src="/images/red.png" alt="Red block" title="<the title>">
|
||||||
|
|
||||||
<!-- Plain image tag with file version -->
|
<!-- Plain image tag with file version -->
|
||||||
<img alt="Red versioned" title="Red versioned" src="/images/red.png?v=W2F5D366_nQ2fQqUk3URdgWy2ZekXjHzHJaY5yaiOOk" />
|
<img alt="Red versioned" title="Red versioned" src="/images/red.png?v=W2F5D366_nQ2fQqUk3URdgWy2ZekXjHzHJaY5yaiOOk" />
|
||||||
|
|
||||||
<!-- Plain image tag with file version set to false -->
|
<!-- Plain image tag with file version set to false -->
|
||||||
<img alt="Red explicitly not versioned" title="Red versioned" src="/images/red.png" />
|
<img alt="Red explicitly not versioned" title="Red versioned" src="/images/red.png" />
|
||||||
|
|
||||||
|
<!-- Plain image tag with absolute path and file version -->
|
||||||
|
<img alt="Absolute path versioned" src="http://contoso.com/hello/world" />
|
||||||
|
|
||||||
|
<!-- Plain image tag with file version and path to file that does not exist -->
|
||||||
|
<img alt="Path to non existing file" src="/images/fake.png" />
|
||||||
|
|
||||||
|
<!-- Plain image tag with file version and path containing query string -->
|
||||||
|
<img alt="Path with query string" src="/images/red.png?abc=def&v=W2F5D366_nQ2fQqUk3URdgWy2ZekXjHzHJaY5yaiOOk" />
|
||||||
|
|
||||||
|
<!-- Plain image tag with file version and path linking to some action -->
|
||||||
|
<img alt="Path linking to some action" src="/controller/action" />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -13,10 +13,22 @@
|
||||||
<!-- Plain image tag -->
|
<!-- Plain image tag -->
|
||||||
<img src="~/images/red.png" alt="Red block" title="<the title>">
|
<img src="~/images/red.png" alt="Red block" title="<the title>">
|
||||||
|
|
||||||
<!-- Plain image tag with file version -->
|
<!-- Plain image tag with file version -->
|
||||||
<img src="~/images/red.png" alt="Red versioned" title="Red versioned" asp-append-version="true" />
|
<img src="~/images/red.png" alt="Red versioned" title="Red versioned" asp-append-version="true" />
|
||||||
|
|
||||||
<!-- Plain image tag with file version set to false -->
|
<!-- Plain image tag with file version set to false -->
|
||||||
<img src="~/images/red.png" alt="Red explicitly not versioned" title="Red versioned" asp-append-version="false" />
|
<img src="~/images/red.png" alt="Red explicitly not versioned" title="Red versioned" asp-append-version="false" />
|
||||||
|
|
||||||
|
<!-- Plain image tag with absolute path and file version -->
|
||||||
|
<img src="http://contoso.com/hello/world" alt="Absolute path versioned" asp-append-version="true" />
|
||||||
|
|
||||||
|
<!-- Plain image tag with file version and path to file that does not exist -->
|
||||||
|
<img src="~/images/fake.png" alt="Path to non existing file" asp-append-version="true" />
|
||||||
|
|
||||||
|
<!-- 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 linking to some action -->
|
||||||
|
<img src="/controller/action" alt="Path linking to some action" asp-append-version="true" />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in New Issue