Updating the UrlRuleProvider to clean up trailing slashes priour to running the comparison

work item: 16798

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-11-22 22:56:57 -08:00
parent 15310bca8b
commit 4773247719
2 changed files with 17 additions and 3 deletions

View File

@@ -61,5 +61,13 @@ namespace Orchard.Tests.Modules.Widgets.RuleEngine {
_urlRuleProvider.Process(context);
Assert.That(context.Result, Is.True);
}
[Test]
public void UrlForAboutPageWithEndingSlashMatchesAboutPagePath() {
_stubContextAccessor.StubContext = new StubHttpContext("~/About/");
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/about" } };
_urlRuleProvider.Process(context);
Assert.That(context.Result, Is.True);
}
}
}

View File

@@ -23,11 +23,17 @@ namespace Orchard.Widgets.RuleEngine {
appPath = "";
url = string.Format("{0}/{1}", appPath, url);
}
if (url != "/" && !url.Contains("?") && url.EndsWith("/"))
if (!url.Contains("?"))
url = url.TrimEnd('/');
var requestPath = context.Request.Path;
if (!requestPath.Contains("?"))
requestPath = requestPath.TrimEnd('/');
ruleContext.Result = url.EndsWith("*")
? context.Request.Path.ToUpperInvariant().StartsWith(url.TrimEnd('*').ToUpperInvariant())
: context.Request.Path.ToUpperInvariant() == url.ToUpperInvariant();
? requestPath.StartsWith(url.TrimEnd('*'), StringComparison.OrdinalIgnoreCase)
: string.Equals(requestPath, url, StringComparison.OrdinalIgnoreCase);
}
}
}