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:
Mateusz Uzdowski 2012-12-18 15:43:05 +13:00 committed by Ingo Schommer
parent 8f239d6373
commit d5a1c3d99a
2 changed files with 12 additions and 4 deletions

View File

@ -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) {

View File

@ -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);