BUGFIX Urlencode paths in URLSegmentFilter when $allowMultibyte=true to avoid creating invalid URLs (and breaking assumptions based on ascii-only URLs, such as static publishing filename creation)

This commit is contained in:
Ingo Schommer 2012-02-06 11:56:26 +01:00
parent 59d31c2fc2
commit 8281678d4c
2 changed files with 9 additions and 5 deletions

View File

@ -64,13 +64,17 @@ class URLSegmentFilter extends Object {
$name = mb_strtolower($name);
$replacements = $this->getReplacements();
if($this->getAllowMultibyte()) {
// unset automated removal of non-ASCII characters, and don't try to transliterate
if(isset($replacements['/[^A-Za-z0-9+.-]+/u'])) unset($replacements['/[^A-Za-z0-9+.-]+/u']);
}
// 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']);
foreach($replacements as $regex => $replace) {
$name = preg_replace($regex, $replace, $name);
}
// Multibyte URLs require percent encoding to comply to RFC 3986.
// Without this setting, the "remove non-ASCII chars" regex takes care of that.
if($this->getAllowMultibyte()) $name = rawurlencode($name);
return $name;
}

View File

@ -27,7 +27,7 @@ class URLSegmentFilterTest extends SapphireTest {
$f = new URLSegmentFilter();
$f->setAllowMultibyte(true);
$this->assertEquals(
'brötchen',
urlencode('brötchen'),
$f->filter('Brötchen')
);
}