Merge pull request #4973 from dhensby/pulls/multibyte-char-fix

Remove question marks, equal signs and hashes
This commit is contained in:
Damian Mooyman 2016-01-25 10:00:07 +13:00
commit f8ce2d7631
2 changed files with 7 additions and 1 deletions

View File

@ -32,7 +32,7 @@ class URLSegmentFilter extends Object {
'/\s|\+/u' => '-', // remove whitespace/plus
'/[_.]+/u' => '-', // underscores and dots to dashes
'/[^A-Za-z0-9\-]+/u' => '', // remove non-ASCII chars, only allow alphanumeric and dashes
'/\/+/u' => '-', // remove forward slashes in case multibyte is allowed (and ASCII chars aren't removed)
'/[\/\?=#]+/u' => '-', // remove forward slashes, question marks, equal signs and hashes in case multibyte is allowed (and non-ASCII chars aren't removed)
'/[\-]{2,}/u' => '-', // remove duplicate dashes
'/^[\-]+/u' => '', // Remove all leading dashes
'/[\-]+$/u' => '' // Remove all trailing dashes

View File

@ -95,5 +95,11 @@ class URLSegmentFilterTest extends SapphireTest {
$filter = new URLSegmentFilter();
$this->assertEquals('url-has-trailing-dashes', $filter->filter('url-has-trailing-dashes--'));
}
public function testRemovesBadCharactersWithMultibyteAllowed() {
$filter = new URLSegmentFilter();
$filter->setAllowMultibyte(true);
$this->assertEquals('url-with-bad-characters', $filter->filter('url?-with/-bad#-characters='));
}
}