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-',
|
||||
'/\s/u' => '-', // remove whitespace
|
||||
'/_/u' => '-', // underscores to dashes
|
||||
'/[^A-Za-z0-9+.\-]+/u' => '', // remove non-ASCII chars, only allow alphanumeric plus dash and dot
|
||||
'/[_.]+/u' => '-', // underscores and dots to dashes
|
||||
'/[^A-Za-z0-9+\-]+/u' => '', // remove non-ASCII chars, only allow alphanumeric and 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();
|
||||
|
||||
// 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) {
|
||||
|
@ -26,7 +26,7 @@ class URLSegmentFilterTest extends SapphireTest {
|
||||
public function testReplacesCommonNonAsciiCharacters() {
|
||||
$f = new URLSegmentFilter();
|
||||
$this->assertEquals(
|
||||
urlencode('aa1-.'),
|
||||
urlencode('aa1-'),
|
||||
$f->filter('Aa1~!@#$%^*()_`-=;\':"[]\{}|,./<>?')
|
||||
);
|
||||
}
|
||||
@ -56,5 +56,10 @@ class URLSegmentFilterTest extends SapphireTest {
|
||||
$f->filter('Tim&Struppi')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testReplacesDots() {
|
||||
$filter = new URLSegmentFilter();
|
||||
$this->assertEquals('url-contains-dot', $filter->filter('url-contains.dot'));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user