Allowing the '/' in slugs.

- Also moved the RoutableServiceTests to a more appropriate location

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-08-26 07:32:45 -07:00
parent cdbdf0db7f
commit f3f04d6ea0
4 changed files with 12 additions and 7 deletions

View File

@@ -101,7 +101,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Common\Providers\CommonPartProviderTests.cs" /> <Compile Include="Common\Providers\CommonPartProviderTests.cs" />
<Compile Include="Common\Services\RoutableServiceTests.cs" /> <Compile Include="Routable\Services\RoutableServiceTests.cs" />
<Compile Include="Feeds\Controllers\FeedControllerTests.cs" /> <Compile Include="Feeds\Controllers\FeedControllerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Scheduling\ScheduledTaskManagerTests.cs" /> <Compile Include="Scheduling\ScheduledTaskManagerTests.cs" />

View File

@@ -24,7 +24,7 @@ using System.Web.Routing;
using Orchard.Tests.Stubs; using Orchard.Tests.Stubs;
using Orchard.UI.Notify; using Orchard.UI.Notify;
namespace Orchard.Core.Tests.Common.Services { namespace Orchard.Core.Tests.Routable.Services {
[TestFixture] [TestFixture]
public class RoutableServiceTests : DatabaseEnabledTestsBase { public class RoutableServiceTests : DatabaseEnabledTestsBase {
[SetUp] [SetUp]
@@ -60,12 +60,17 @@ namespace Orchard.Core.Tests.Common.Services {
var thing = contentManager.Create<Thing>(ThingDriver.ContentType.Name, t => { var thing = contentManager.Create<Thing>(ThingDriver.ContentType.Name, 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 slugs: \":\", \"/\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\""; t.Title = "Please do not use any of the following characters in your slugs: \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\"";
}); });
_routableService.FillSlugFromTitle(thing.As<RoutePart>()); _routableService.FillSlugFromTitle(thing.As<RoutePart>());
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] [Test]
@@ -80,7 +85,7 @@ namespace Orchard.Core.Tests.Common.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

@@ -78,7 +78,7 @@ namespace Orchard.Core.Routable.Drivers {
part.Slug = model.Slug; part.Slug = model.Slug;
if (!_routableService.IsSlugValid(part.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; string originalSlug = part.Slug;

View File

@@ -64,7 +64,7 @@ namespace Orchard.Core.Routable.Services {
public bool IsSlugValid(string slug) { public bool IsSlugValid(string slug) {
// see http://tools.ietf.org/html/rfc3987 for prohibited chars // 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) { public bool ProcessSlug(RoutePart part) {