Skip to content

Commit 45b6307

Browse files
committed
Fix issues with relative url, target net45
1 parent 28cd8c7 commit 45b6307

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

AspNet.MVC5.AssetVersioning.Tests/ExtensionsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ public class ExtensionsTests
1616
public void AppendVersion_Should_Append_To_Empty_Url()
1717
{
1818

19-
var path = Extensions.AppendVersion("https://foo.com/test.js", "123");
19+
var path = Extensions.AppendVersion("/test.js", "123");
2020

21-
Assert.AreEqual("https://foo.com/test.js?123", path);
21+
Assert.AreEqual("/test.js?123", path);
2222
}
2323

2424
[TestMethod]
2525
public void AppendVersion_Should_Append_To_Existing_Url()
2626
{
2727

28-
var path = Extensions.AppendVersion("https://foo.com/test.js?h=foo", "123");
28+
var path = Extensions.AppendVersion("/test.js?h=foo", "123");
2929

30-
Assert.AreEqual("https://foo.com/test.js?h=foo&123", path);
30+
Assert.AreEqual("/test.js?h=foo&123", path);
3131
}
3232

3333
[TestMethod]

src/AspNet.MVC5.AssetVersioning.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>AspNet.MVC5.AssetVersioning</RootNamespace>
1111
<AssemblyName>AspNet.MVC5.AssetVersioning</AssemblyName>
12-
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<Deterministic>true</Deterministic>
15+
<TargetFrameworkProfile />
1516
</PropertyGroup>
1617
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1718
<DebugSymbols>true</DebugSymbols>

src/AspNet.MVC5.AssetVersioning.csproj.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>AspNet.Mvc.AssetVersioning</id>
5-
<version>1.0.527</version>
5+
<version>1.1.527</version>
66
<authors>kayub</authors>
77
<owners>kayub</owners>
88
<licenseUrl>https://github.com/kamranayub/aspnetmvc5-asset-versioning</licenseUrl>

src/Extensions.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,29 @@ public static class Extensions
1010
{
1111
public static string AppendVersion(string contentUrl, string version)
1212
{
13-
var url = new UriBuilder(contentUrl);
14-
if (url.Query != null && url.Query.Length > 1)
15-
url.Query = url.Query.Substring(1) + "&" + version;
13+
if (contentUrl.Contains("?"))
14+
{
15+
return contentUrl + "&" + version;
16+
}
1617
else
17-
url.Query = version;
18-
19-
return url.Uri.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.PathAndQuery, UriFormat.Unescaped);
18+
{
19+
return contentUrl + "?" + version;
20+
}
2021
}
2122

22-
public static string VersionedContent(this UrlHelper helper, string assetPath)
23+
public static string VersionedContent(this UrlHelper helper, string contentPath)
2324
{
24-
var fullPath = helper.RequestContext.HttpContext.Server.MapPath(assetPath);
25+
var fullPath = helper.RequestContext.HttpContext.Server.MapPath(contentPath);
2526
var version = AssetVersionCache.GetOrAddCachedVersion(fullPath, helper.RequestContext.HttpContext.Cache);
2627

27-
if (version != null) {
28+
if (version != null)
29+
{
30+
var relativePath = helper.Content(contentPath);
2831
// append hash to query string
29-
return Extensions.AppendVersion(helper.Content(assetPath), version);
32+
return AppendVersion(relativePath, version);
3033
}
3134

32-
return helper.Content(assetPath);
35+
return helper.Content(contentPath);
3336
}
3437
}
3538
}

src/packages.config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net472" />
4-
<package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net472" />
5-
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net472" />
6-
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net472" />
3+
<package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net45" />
4+
<package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net45" />
5+
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net45" />
6+
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
77
</packages>

0 commit comments

Comments
 (0)