Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUG Fixes issue with '+' characters in url.

  • Loading branch information...
commit de41a2a75e619985c70a2946276ca3a9b6730890 1 parent c1d25d1
@tractorcow tractorcow authored
Showing with 19 additions and 4 deletions.
  1. +4 −4 model/URLSegmentFilter.php
  2. +15 −0 tests/model/URLSegmentFilterTest.php
View
8 model/URLSegmentFilter.php
@@ -29,9 +29,9 @@ class URLSegmentFilter extends Object {
private static $default_replacements = array(
'/&/u' => '-and-',
'/&/u' => '-and-',
- '/\s/u' => '-', // remove whitespace
+ '/\s|\+/u' => '-', // remove whitespace/plus
'/[_.]+/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
'/[\-]{2,}/u' => '-', // remove duplicate dashes
'/^[\-_]/u' => '', // Remove all leading dashes or underscores
);
@@ -69,8 +69,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) {
View
15 tests/model/URLSegmentFilterTest.php
@@ -5,6 +5,8 @@
*/
class URLSegmentFilterTest extends SapphireTest {
+ protected $usesDatabase = false;
+
public function testReplacesCommonEnglishSymbols() {
$f = new URLSegmentFilter();
$f->setAllowMultibyte(false);
@@ -14,6 +16,19 @@ public function testReplacesCommonEnglishSymbols() {
);
}
+ public function testReplacesWhitespace() {
+ $f = new URLSegmentFilter();
+ $f->setAllowMultibyte(false);
+ $this->assertEquals(
+ 'john-and-spencer',
+ $f->filter('John and Spencer')
+ );
+ $this->assertEquals(
+ 'john-and-spencer',
+ $f->filter('John+and+Spencer')
+ );
+ }
+
public function testTransliteratesNonAsciiUrls() {
$f = new URLSegmentFilter();
$f->setAllowMultibyte(false);
Please sign in to comment.
Something went wrong with that request. Please try again.