mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #4973 from dhensby/pulls/multibyte-char-fix
Remove question marks, equal signs and hashes
This commit is contained in:
commit
f8ce2d7631
@ -32,7 +32,7 @@ class URLSegmentFilter extends Object {
|
|||||||
'/\s|\+/u' => '-', // remove whitespace/plus
|
'/\s|\+/u' => '-', // remove whitespace/plus
|
||||||
'/[_.]+/u' => '-', // underscores and dots to dashes
|
'/[_.]+/u' => '-', // underscores and dots to dashes
|
||||||
'/[^A-Za-z0-9\-]+/u' => '', // remove non-ASCII chars, only allow alphanumeric and 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
|
'/[\-]{2,}/u' => '-', // remove duplicate dashes
|
||||||
'/^[\-]+/u' => '', // Remove all leading dashes
|
'/^[\-]+/u' => '', // Remove all leading dashes
|
||||||
'/[\-]+$/u' => '' // Remove all trailing dashes
|
'/[\-]+$/u' => '' // Remove all trailing dashes
|
||||||
|
@ -95,5 +95,11 @@ class URLSegmentFilterTest extends SapphireTest {
|
|||||||
$filter = new URLSegmentFilter();
|
$filter = new URLSegmentFilter();
|
||||||
$this->assertEquals('url-has-trailing-dashes', $filter->filter('url-has-trailing-dashes--'));
|
$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='));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user