mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Allowing the '/' in slugs.
- Also moved the RoutableServiceTests to a more appropriate location --HG-- branch : dev
This commit is contained in:
@@ -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" />
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -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;
|
||||||
|
@@ -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) {
|
||||||
|
Reference in New Issue
Block a user