Adding a test for slugs

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-10-14 16:55:09 -07:00
parent a49112c177
commit ff91690cfb
2 changed files with 8 additions and 7 deletions

View File

@@ -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

View File

@@ -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) {