Remove trailing dashes from URLSegment

This commit is contained in:
Colin Richardson 2014-03-03 22:22:03 +00:00
parent 78678acdad
commit 7b13041449
2 changed files with 9 additions and 3 deletions

View File

@ -33,7 +33,8 @@ class URLSegmentFilter extends Object {
'/[_.]+/u' => '-', // underscores and dots to dashes
'/[^A-Za-z0-9\-]+/u' => '', // remove non-ASCII chars, only allow alphanumeric and dashes
'/[\-]{2,}/u' => '-', // remove duplicate dashes
'/^[\-]+/u' => '' // Remove all leading dashes
'/^[\-]+/u' => '', // Remove all leading dashes
'/[\-]+$/u' => '' // Remove all trailing dashes
);
/**

View File

@ -41,8 +41,8 @@ class URLSegmentFilterTest extends SapphireTest {
public function testReplacesCommonNonAsciiCharacters() {
$f = new URLSegmentFilter();
$this->assertEquals(
urlencode('aa1-'),
$f->filter('Aa1~!@#$%^*()_`-=;\':"[]\{}|,./<>?')
urlencode('aa1-a'),
$f->filter('Aa1~!@#$%^*()_`-=;\':"[]\{}|,./<>?a')
);
}
@ -82,4 +82,9 @@ class URLSegmentFilterTest extends SapphireTest {
$this->assertEquals('url-has-leading-dashes', $filter->filter('---url-has-leading-dashes'));
}
public function testReplacesTrailingDashes() {
$filter = new URLSegmentFilter();
$this->assertEquals('url-has-trailing-dashes', $filter->filter('url-has-trailing-dashes--'));
}
}