mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
59d31c2fc2
commit
8281678d4c
@ -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;
|
||||
}
|
||||
|
@ -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')
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user