mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Adding a test for slugs
--HG-- branch : dev
This commit is contained in:
@@ -84,6 +84,13 @@ namespace Orchard.Core.Tests.Routable.Services {
|
||||
Assert.That(_routableService.IsSlugValid("some/page"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DotsAroundSlugAreAllowed() {
|
||||
Assert.That(_routableService.IsSlugValid(".slug"), Is.False);
|
||||
Assert.That(_routableService.IsSlugValid("slug."), Is.False);
|
||||
Assert.That(_routableService.IsSlugValid("slug.slug"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmptySlugsShouldBeConsideredValid() {
|
||||
// so that automatic generation on Publish occurs
|
||||
|
@@ -66,13 +66,7 @@ namespace Orchard.Core.Routable.Services {
|
||||
}
|
||||
|
||||
public bool IsSlugValid(string slug) {
|
||||
slug = (slug ?? String.Empty).Trim();
|
||||
return !( SlugHasProhibitedChard(slug) || slug.StartsWith(".") || slug.EndsWith(".") );
|
||||
}
|
||||
|
||||
public bool SlugHasProhibitedChard(string slug) {
|
||||
// see http://tools.ietf.org/html/rfc3987 for prohibited chars
|
||||
return Regex.IsMatch(slug, @"^[^:?#\[\]@!$&'()*+,;=\s]+$");
|
||||
return String.IsNullOrWhiteSpace(slug) || Regex.IsMatch(slug, @"^[^:?#\[\]@!$&'()*+,;=\s]+$") && !(slug.StartsWith(".") || slug.EndsWith("."));
|
||||
}
|
||||
|
||||
public bool ProcessSlug(RoutePart part) {
|
||||
|
Reference in New Issue
Block a user