Merge pull request #1349 from ajshort/pulls/urlsegment-filter-dots

API: Don't allow dots in URL segments
This commit is contained in:
Ingo Schommer 2013-03-30 02:30:20 -07:00
commit 94ea56b604
2 changed files with 12 additions and 7 deletions

View File

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

View File

@ -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'));
}
}