BUG Fixes issue with '+' characters in url.

This commit is contained in:
Damian Mooyman 2013-05-10 16:10:26 +12:00
parent c1d25d17ce
commit de41a2a75e
2 changed files with 19 additions and 4 deletions

View File

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

@ -5,6 +5,8 @@
*/
class URLSegmentFilterTest extends SapphireTest {
protected $usesDatabase = false;
public function testReplacesCommonEnglishSymbols() {
$f = new URLSegmentFilter();
$f->setAllowMultibyte(false);
@ -14,6 +16,19 @@ class URLSegmentFilterTest extends SapphireTest {
);
}
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);