mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02: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-',
|
'/&/u' => '-and-',
|
||||||
'/\s/u' => '-', // remove whitespace
|
'/\s/u' => '-', // remove whitespace
|
||||||
'/_/u' => '-', // underscores to dashes
|
'/_/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
|
'/[\-]{2,}/u' => '-', // remove duplicate dashes
|
||||||
'/^[\.\-_]/u' => '', // Remove all leading dots, dashes or underscores
|
'/^[\.\-_]/u' => '', // Remove all leading dots, dashes or underscores
|
||||||
);
|
);
|
||||||
@ -66,8 +66,8 @@ class URLSegmentFilter extends Object {
|
|||||||
$replacements = $this->getReplacements();
|
$replacements = $this->getReplacements();
|
||||||
|
|
||||||
// Unset automated removal of non-ASCII characters, and don't try to transliterate
|
// Unset automated removal of non-ASCII characters, and don't try to transliterate
|
||||||
if($this->getAllowMultibyte() && isset($replacements['/[^A-Za-z0-9+.-]+/u'])) {
|
if($this->getAllowMultibyte() && isset($replacements['/[^A-Za-z0-9.-]+/u'])) {
|
||||||
unset($replacements['/[^A-Za-z0-9+.-]+/u']);
|
unset($replacements['/[^A-Za-z0-9.-]+/u']);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($replacements as $regex => $replace) {
|
foreach($replacements as $regex => $replace) {
|
||||||
|
@ -23,6 +23,14 @@ class URLSegmentFilterTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testReplacesCommonNonAsciiCharacters() {
|
||||||
|
$f = new URLSegmentFilter();
|
||||||
|
$this->assertEquals(
|
||||||
|
urlencode('aa1-.'),
|
||||||
|
$f->filter('Aa1~!@#$%^*()_+`-=;\':"[]\{}|,./<>?')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testRetainsNonAsciiUrlsWithAllowMultiByteOption() {
|
public function testRetainsNonAsciiUrlsWithAllowMultiByteOption() {
|
||||||
$f = new URLSegmentFilter();
|
$f = new URLSegmentFilter();
|
||||||
$f->setAllowMultibyte(true);
|
$f->setAllowMultibyte(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user