Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Allow for file names with no extension:
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianEdwards committed Feb 24, 2015
1 parent 16c1166 commit 352af96
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Microsoft.AspNet.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
};
}
Expand Down

0 comments on commit 352af96

Please sign in to comment.