Forbidding the use of backslashes in slugs.

work item: 16593

--HG--
branch : 1.x
This commit is contained in:
Nathan Heskew 2011-04-05 13:32:43 -07:00
parent dd210ab801
commit 48975f4ca4
3 changed files with 5 additions and 5 deletions

View File

@ -72,7 +72,7 @@ namespace Orchard.Core.Tests.Routable.Services {
var thing = contentManager.Create<Thing>("thing", t => { var thing = contentManager.Create<Thing>("thing", t => {
t.As<RoutePart>().Record = new RoutePartRecord(); t.As<RoutePart>().Record = new RoutePartRecord();
t.Title = "Please do not use any of the following characters in your permalink: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\", \"\"\", \"<\", \">\""; t.Title = "Please do not use any of the following characters in your permalink: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\", \"\"\", \"<\", \">\", \"\\\"";
}); });
_routableService.FillSlugFromTitle(thing.As<RoutePart>()); _routableService.FillSlugFromTitle(thing.As<RoutePart>());
@ -120,7 +120,7 @@ namespace Orchard.Core.Tests.Routable.Services {
public void InvalidCharacterShouldBeRefusedInSlugs() { public void InvalidCharacterShouldBeRefusedInSlugs() {
Assert.That(_routableService.IsSlugValid("aaaa-_aaaa"), Is.True); Assert.That(_routableService.IsSlugValid("aaaa-_aaaa"), Is.True);
foreach (var c in @":?#[]@!$&'()*+,;= ") { foreach (var c in @":?#[]@!$&'()*+,;= \") {
Assert.That(_routableService.IsSlugValid("a" + c + "b"), Is.False); Assert.That(_routableService.IsSlugValid("a" + c + "b"), Is.False);
} }
} }

View File

@ -89,7 +89,7 @@ namespace Orchard.Core.Routable.Drivers {
if ( slug.StartsWith(".") || slug.EndsWith(".") ) if ( slug.StartsWith(".") || slug.EndsWith(".") )
updater.AddModelError("Routable.Slug", T("The \".\" can't be used at either end of the permalink.")); updater.AddModelError("Routable.Slug", T("The \".\" can't be used at either end of the permalink."));
else else
updater.AddModelError("Routable.Slug", T("Please do not use any of the following characters in your permalink: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\", \", \"<\", \">\". No spaces are allowed (please use dashes or underscores instead).")); updater.AddModelError("Routable.Slug", T("Please do not use any of the following characters in your permalink: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\", \", \"<\", \">\", \"\\\". No spaces are allowed (please use dashes or underscores instead)."));
} }
return Editor(part, shapeHelper); return Editor(part, shapeHelper);

View File

@ -57,7 +57,7 @@ namespace Orchard.Core.Routable.Services {
} }
if (!slugContext.Adjusted) { if (!slugContext.Adjusted) {
var disallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s\""\<\>]+"); var disallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s\""\<\>\\]+");
slugContext.Slug = disallowed.Replace(slugContext.Slug, "-").Trim('-'); slugContext.Slug = disallowed.Replace(slugContext.Slug, "-").Trim('-');
@ -108,7 +108,7 @@ namespace Orchard.Core.Routable.Services {
} }
public bool IsSlugValid(string slug) { public bool IsSlugValid(string slug) {
return String.IsNullOrWhiteSpace(slug) || Regex.IsMatch(slug, @"^[^:?#\[\]@!$&'()*+,;=\s\""\<\>]+$") && !(slug.StartsWith(".") || slug.EndsWith(".")); return String.IsNullOrWhiteSpace(slug) || Regex.IsMatch(slug, @"^[^:?#\[\]@!$&'()*+,;=\s\""\<\>\\]+$") && !(slug.StartsWith(".") || slug.EndsWith("."));
} }
public bool ProcessSlug(IRoutableAspect part) { public bool ProcessSlug(IRoutableAspect part) {