From 327d7f3a08d99dc4cb4e3ad64732e052ece8675e Mon Sep 17 00:00:00 2001 From: salar2k Date: Thu, 5 Jun 2014 14:06:04 +0430 Subject: [PATCH] Only 'controller' and 'action' should get trailing dash. --- .../LowercaseDashedRoute.cs | 32 ++++++------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/LowercaseDashedRouting/LowercaseDashedRoute.cs b/LowercaseDashedRouting/LowercaseDashedRoute.cs index d6744f9..d7c6cc6 100644 --- a/LowercaseDashedRouting/LowercaseDashedRoute.cs +++ b/LowercaseDashedRouting/LowercaseDashedRoute.cs @@ -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); } /// @@ -142,9 +131,6 @@ public override VirtualPathData GetVirtualPath(RequestContext requestContext, Ro /// dashed text protected static string AddDashesBeforeCapitals(string text) { - if (string.IsNullOrWhiteSpace(text)) - return string.Empty; - var newText = new StringBuilder(text.Length * 2); newText.Append(text[0]);