mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Updating the UrlRuleProvider to clean up trailing slashes priour to running the comparison
work item: 16798 --HG-- branch : dev
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user