From f3f04d6ea045ab04fbb82c13d26d207573a7f5c0 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Thu, 26 Aug 2010 07:32:45 -0700 Subject: [PATCH] Allowing the '/' in slugs. - Also moved the RoutableServiceTests to a more appropriate location --HG-- branch : dev --- src/Orchard.Core.Tests/Orchard.Core.Tests.csproj | 2 +- .../Services/RoutableServiceTests.cs | 13 +++++++++---- .../Core/Routable/Drivers/RoutePartDriver.cs | 2 +- .../Core/Routable/Services/RoutableService.cs | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) rename src/Orchard.Core.Tests/{Common => Routable}/Services/RoutableServiceTests.cs (94%) diff --git a/src/Orchard.Core.Tests/Orchard.Core.Tests.csproj b/src/Orchard.Core.Tests/Orchard.Core.Tests.csproj index 7eab2d21c..1c720d5d5 100644 --- a/src/Orchard.Core.Tests/Orchard.Core.Tests.csproj +++ b/src/Orchard.Core.Tests/Orchard.Core.Tests.csproj @@ -101,7 +101,7 @@ - + diff --git a/src/Orchard.Core.Tests/Common/Services/RoutableServiceTests.cs b/src/Orchard.Core.Tests/Routable/Services/RoutableServiceTests.cs similarity index 94% rename from src/Orchard.Core.Tests/Common/Services/RoutableServiceTests.cs rename to src/Orchard.Core.Tests/Routable/Services/RoutableServiceTests.cs index a08d40c8c..62b493e66 100644 --- a/src/Orchard.Core.Tests/Common/Services/RoutableServiceTests.cs +++ b/src/Orchard.Core.Tests/Routable/Services/RoutableServiceTests.cs @@ -24,7 +24,7 @@ using System.Web.Routing; using Orchard.Tests.Stubs; using Orchard.UI.Notify; -namespace Orchard.Core.Tests.Common.Services { +namespace Orchard.Core.Tests.Routable.Services { [TestFixture] public class RoutableServiceTests : DatabaseEnabledTestsBase { [SetUp] @@ -60,12 +60,17 @@ namespace Orchard.Core.Tests.Common.Services { var thing = contentManager.Create(ThingDriver.ContentType.Name, t => { t.As().Record = new RoutePartRecord(); - t.Title = "Please do not use any of the following characters in your slugs: \":\", \"/\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\""; + t.Title = "Please do not use any of the following characters in your slugs: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\""; }); _routableService.FillSlugFromTitle(thing.As()); - Assert.That(thing.Slug, Is.EqualTo("please-do-not-use-any-of-the-following-characters-in-your-slugs-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"")); + Assert.That(thing.Slug, Is.EqualTo("please-do-not-use-any-of-the-following-characters-in-your-slugs-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"")); + } + + [Test] + public void SlashInSlugIsAllowed() { + Assert.That(_routableService.IsSlugValid("some/page"), Is.True); } [Test] @@ -80,7 +85,7 @@ namespace Orchard.Core.Tests.Common.Services { public void InvalidCharacterShouldBeRefusedInSlugs() { 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); } } diff --git a/src/Orchard.Web/Core/Routable/Drivers/RoutePartDriver.cs b/src/Orchard.Web/Core/Routable/Drivers/RoutePartDriver.cs index 451b97c97..727184b00 100644 --- a/src/Orchard.Web/Core/Routable/Drivers/RoutePartDriver.cs +++ b/src/Orchard.Web/Core/Routable/Drivers/RoutePartDriver.cs @@ -78,7 +78,7 @@ namespace Orchard.Core.Routable.Drivers { part.Slug = model.Slug; if (!_routableService.IsSlugValid(part.Slug)) { - updater.AddModelError("Routable.Slug", T("Please do not use any of the following characters in your slugs: \"/\", \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\". 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 slugs: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\". No spaces are allowed (please use dashes or underscores instead).")); } string originalSlug = part.Slug; diff --git a/src/Orchard.Web/Core/Routable/Services/RoutableService.cs b/src/Orchard.Web/Core/Routable/Services/RoutableService.cs index a35caf878..7d29d7397 100644 --- a/src/Orchard.Web/Core/Routable/Services/RoutableService.cs +++ b/src/Orchard.Web/Core/Routable/Services/RoutableService.cs @@ -64,7 +64,7 @@ namespace Orchard.Core.Routable.Services { public bool IsSlugValid(string slug) { // see http://tools.ietf.org/html/rfc3987 for prohibited chars - return slug == null || String.IsNullOrEmpty(slug.Trim()) || Regex.IsMatch(slug, @"^[^/:?#\[\]@!$&'()*+,;=\s]+$"); + return slug == null || String.IsNullOrEmpty(slug.Trim()) || Regex.IsMatch(slug, @"^[^:?#\[\]@!$&'()*+,;=\s]+$"); } public bool ProcessSlug(RoutePart part) {