Merge pull request #2871 from feejin/urlsegment-trailing-space

BUG Trim URLSegment before applying replacements in filter
This commit is contained in:
Damian Mooyman 2014-03-06 08:16:31 +13:00
commit cad863204c
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--'));
}
}