Permalink
Browse files

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
  • Loading branch information...
1 parent 8f239d6 commit d5a1c3d99a4218e15ec2bb35d9f031152f7958e8 @mateusz mateusz committed with chillu Dec 18, 2012
Showing with 12 additions and 4 deletions.
  1. +3 −3 model/URLSegmentFilter.php
  2. +9 −1 tests/model/URLSegmentFilterTest.php
@@ -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 @@ public function filter($name) {
$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 @@ public function testTransliteratesNonAsciiUrls() {
$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);

0 comments on commit d5a1c3d

Please sign in to comment.