mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #1349 from ajshort/pulls/urlsegment-filter-dots
API: Don't allow dots in URL segments
This commit is contained in:
commit
94ea56b604
@ -30,10 +30,10 @@ class URLSegmentFilter extends Object {
|
|||||||
'/&/u' => '-and-',
|
'/&/u' => '-and-',
|
||||||
'/&/u' => '-and-',
|
'/&/u' => '-and-',
|
||||||
'/\s/u' => '-', // remove whitespace
|
'/\s/u' => '-', // remove whitespace
|
||||||
'/_/u' => '-', // underscores to dashes
|
'/[_.]+/u' => '-', // underscores and dots 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 and dashes
|
||||||
'/[\-]{2,}/u' => '-', // remove duplicate dashes
|
'/[\-]{2,}/u' => '-', // remove duplicate dashes
|
||||||
'/^[\.\-_]/u' => '', // Remove all leading dots, 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) {
|
||||||
|
@ -26,7 +26,7 @@ class URLSegmentFilterTest extends SapphireTest {
|
|||||||
public function testReplacesCommonNonAsciiCharacters() {
|
public function testReplacesCommonNonAsciiCharacters() {
|
||||||
$f = new URLSegmentFilter();
|
$f = new URLSegmentFilter();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
urlencode('aa1-.'),
|
urlencode('aa1-'),
|
||||||
$f->filter('Aa1~!@#$%^*()_`-=;\':"[]\{}|,./<>?')
|
$f->filter('Aa1~!@#$%^*()_`-=;\':"[]\{}|,./<>?')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -57,4 +57,9 @@ class URLSegmentFilterTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testReplacesDots() {
|
||||||
|
$filter = new URLSegmentFilter();
|
||||||
|
$this->assertEquals('url-contains-dot', $filter->filter('url-contains.dot'));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user