mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUG SS has problems handling + in URLs. Filter them out.
+ has a special meaning in the URLs so overall it's a good idea to strip them out. Otherwise they would need to appear in their ugly url encoded form "%2B". Refer: http://open.silverstripe.org/ticket/7929
This commit is contained in:
parent
8f239d6373
commit
d5a1c3d99a
@ -29,7 +29,7 @@ class URLSegmentFilter extends Object {
|
||||
'/&/u' => '-and-',
|
||||
'/\s/u' => '-', // remove whitespace
|
||||
'/_/u' => '-', // underscores to dashes
|
||||
'/[^A-Za-z0-9+.-]+/u' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot
|
||||
'/[^A-Za-z0-9.-]+/u' => '', // remove non-ASCII chars, only allow alphanumeric, dashes and dots.
|
||||
'/[\-]{2,}/u' => '-', // remove duplicate dashes
|
||||
'/^[\.\-_]/u' => '', // Remove all leading dots, dashes or underscores
|
||||
);
|
||||
@ -66,8 +66,8 @@ class URLSegmentFilter extends Object {
|
||||
$replacements = $this->getReplacements();
|
||||
|
||||
// Unset automated removal of non-ASCII characters, and don't try to transliterate
|
||||
if($this->getAllowMultibyte() && isset($replacements['/[^A-Za-z0-9+.-]+/u'])) {
|
||||
unset($replacements['/[^A-Za-z0-9+.-]+/u']);
|
||||
if($this->getAllowMultibyte() && isset($replacements['/[^A-Za-z0-9.-]+/u'])) {
|
||||
unset($replacements['/[^A-Za-z0-9.-]+/u']);
|
||||
}
|
||||
|
||||
foreach($replacements as $regex => $replace) {
|
||||
|
@ -22,7 +22,15 @@ class URLSegmentFilterTest extends SapphireTest {
|
||||
$f->filter('Brötchen')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testReplacesCommonNonAsciiCharacters() {
|
||||
$f = new URLSegmentFilter();
|
||||
$this->assertEquals(
|
||||
urlencode('aa1-.'),
|
||||
$f->filter('Aa1~!@#$%^*()_+`-=;\':"[]\{}|,./<>?')
|
||||
);
|
||||
}
|
||||
|
||||
public function testRetainsNonAsciiUrlsWithAllowMultiByteOption() {
|
||||
$f = new URLSegmentFilter();
|
||||
$f->setAllowMultibyte(true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user