mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +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);
|
_urlRuleProvider.Process(context);
|
||||||
Assert.That(context.Result, Is.True);
|
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 = "";
|
appPath = "";
|
||||||
url = string.Format("{0}/{1}", appPath, url);
|
url = string.Format("{0}/{1}", appPath, url);
|
||||||
}
|
}
|
||||||
if (url != "/" && !url.Contains("?") && url.EndsWith("/"))
|
|
||||||
|
if (!url.Contains("?"))
|
||||||
url = url.TrimEnd('/');
|
url = url.TrimEnd('/');
|
||||||
|
|
||||||
|
var requestPath = context.Request.Path;
|
||||||
|
if (!requestPath.Contains("?"))
|
||||||
|
requestPath = requestPath.TrimEnd('/');
|
||||||
|
|
||||||
ruleContext.Result = url.EndsWith("*")
|
ruleContext.Result = url.EndsWith("*")
|
||||||
? context.Request.Path.ToUpperInvariant().StartsWith(url.TrimEnd('*').ToUpperInvariant())
|
? requestPath.StartsWith(url.TrimEnd('*'), StringComparison.OrdinalIgnoreCase)
|
||||||
: context.Request.Path.ToUpperInvariant() == url.ToUpperInvariant();
|
: string.Equals(requestPath, url, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user