diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs index ac8c1bb4d1..6120814dac 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs @@ -153,14 +153,22 @@ public int Compare(string x, string y) var xExtIndex = x.LastIndexOf('.'); var yExtIndex = y.LastIndexOf('.'); - var xNoExt = x.Substring(0, xExtIndex); - var yNoExt = y.Substring(0, yExtIndex); + // Ensure extension index is in the last segment, i.e. in the file name + var xSlashIndex = x.LastIndexOf('/'); + var ySlashIndex = y.LastIndexOf('/'); + xExtIndex = xExtIndex > xSlashIndex ? xExtIndex : -1; + yExtIndex = yExtIndex > ySlashIndex ? yExtIndex : -1; + + // Get paths without their extensions, if they have one + var xNoExt = xExtIndex >= 0 ? x.Substring(0, xExtIndex) : x; + var yNoExt = yExtIndex >= 0 ? y.Substring(0, yExtIndex) : y; if (xNoExt.Equals(yNoExt)) { // Only extension differs so just compare the extension - var xExt = x.Substring(xExtIndex); - var yExt = y.Substring(yExtIndex); + var xExt = xExtIndex >= 0 ? x.Substring(xExtIndex) : string.Empty; + var yExt = yExtIndex >= 0 ? y.Substring(yExtIndex) : string.Empty; + return xExt.CompareTo(yExt); } diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/GlobbingUrlBuilderTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/GlobbingUrlBuilderTest.cs index 3738eb809b..676f6a5261 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/GlobbingUrlBuilderTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/GlobbingUrlBuilderTest.cs @@ -163,6 +163,44 @@ public static TheoryData OrdersGlobbedMatchResultsCorrectly_Data "/A/site11.css", "/A/site2.css", "/B/site11.css", "/B/site2.css" } + }, + { + /* staticUrl */ "/site.css", + /* dirStructure */ new FileNode(null, new [] { + new FileNode("B", new [] { + new FileNode("site"), + new FileNode("site.css") + }), + new FileNode("A", new [] { + new FileNode("site.css"), + new FileNode("site") + }) + }), + /* expectedPaths */ new [] + { + "/site.css", + "/A/site", "/A/site.css", + "/B/site", "/B/site.css" + } + }, + { + /* staticUrl */ "/site.css", + /* dirStructure */ new FileNode(null, new [] { + new FileNode("B.B", new [] { + new FileNode("site"), + new FileNode("site.css") + }), + new FileNode("A.A", new [] { + new FileNode("site.css"), + new FileNode("site") + }) + }), + /* expectedPaths */ new [] + { + "/site.css", + "/A.A/site", "/A.A/site.css", + "/B.B/site", "/B.B/site.css" + } } }; }