mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #1867 from tractorcow/3.1-urlsegmentfilter-fixes
BUG Fixes issue with "+" characters in url.
This commit is contained in:
commit
13e632d053
@ -29,9 +29,9 @@ class URLSegmentFilter extends Object {
|
|||||||
private static $default_replacements = array(
|
private static $default_replacements = array(
|
||||||
'/&/u' => '-and-',
|
'/&/u' => '-and-',
|
||||||
'/&/u' => '-and-',
|
'/&/u' => '-and-',
|
||||||
'/\s/u' => '-', // remove whitespace
|
'/\s|\+/u' => '-', // remove whitespace/plus
|
||||||
'/[_.]+/u' => '-', // underscores and dots to dashes
|
'/[_.]+/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
|
'/[\-]{2,}/u' => '-', // remove duplicate dashes
|
||||||
'/^[\-_]/u' => '', // Remove all leading dashes or underscores
|
'/^[\-_]/u' => '', // Remove all leading dashes or underscores
|
||||||
);
|
);
|
||||||
@ -69,8 +69,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) {
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
class URLSegmentFilterTest extends SapphireTest {
|
class URLSegmentFilterTest extends SapphireTest {
|
||||||
|
|
||||||
|
protected $usesDatabase = false;
|
||||||
|
|
||||||
public function testReplacesCommonEnglishSymbols() {
|
public function testReplacesCommonEnglishSymbols() {
|
||||||
$f = new URLSegmentFilter();
|
$f = new URLSegmentFilter();
|
||||||
$f->setAllowMultibyte(false);
|
$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() {
|
public function testTransliteratesNonAsciiUrls() {
|
||||||
$f = new URLSegmentFilter();
|
$f = new URLSegmentFilter();
|
||||||
$f->setAllowMultibyte(false);
|
$f->setAllowMultibyte(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user