Skip to content

Commit

Permalink
Only 'controller' and 'action' should get trailing dash.
Browse files Browse the repository at this point in the history
  • Loading branch information
salarcode committed Jun 5, 2014
1 parent 285a184 commit 327d7f3
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions LowercaseDashedRouting/LowercaseDashedRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,18 @@ public LowercaseDashedRoute(string url, RouteValueDictionary defaults, RouteValu

public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
VirtualPathData path = base.GetVirtualPath(requestContext, values);

if (path != null)
var action = values["action"] as string;
var controller = values["controller"] as string;
if (!string.IsNullOrEmpty(action))
{
string virtualPath = path.VirtualPath;
var lastIndexOf = virtualPath.LastIndexOf("?", System.StringComparison.InvariantCulture);

if (lastIndexOf != 0)
{
if (lastIndexOf > 0)
{
string leftPart = AddDashesBeforeCapitals(virtualPath.Substring(0, lastIndexOf)).ToLowerInvariant();
string queryPart = virtualPath.Substring(lastIndexOf);
path.VirtualPath = leftPart + queryPart;
}
else
{
path.VirtualPath = AddDashesBeforeCapitals(path.VirtualPath).ToLowerInvariant();
}
}
values["action"] = AddDashesBeforeCapitals(action).ToLowerInvariant();
}

return path;
if (!string.IsNullOrEmpty(controller))
{
values["controller"] = AddDashesBeforeCapitals(controller).ToLowerInvariant();
}
return base.GetVirtualPath(requestContext, values);
}

/// <summary>
Expand All @@ -142,9 +131,6 @@ public override VirtualPathData GetVirtualPath(RequestContext requestContext, Ro
/// <returns>dashed text</returns>
protected static string AddDashesBeforeCapitals(string text)
{
if (string.IsNullOrWhiteSpace(text))
return string.Empty;

var newText = new StringBuilder(text.Length * 2);
newText.Append(text[0]);

Expand Down

0 comments on commit 327d7f3

Please sign in to comment.