mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #413 from chillu/urlsegment-multibyte-fix
URLSegment multibyte fixes
This commit is contained in:
commit
9950fa362e
@ -152,7 +152,7 @@ class SS_HTTPResponse {
|
||||
$this->body = $body;
|
||||
|
||||
// Set content-length in bytes. Use mbstring to avoid problems with mb_internal_encoding() and mbstring.func_overload
|
||||
$this->headers['Content-Length'] = (function_exists('mb_strlen') ? mb_strlen($this->body,'8bit') : strlen($this->body));
|
||||
$this->headers['Content-Length'] = mb_strlen($this->body,'8bit');
|
||||
}
|
||||
|
||||
function getBody() {
|
||||
|
@ -64,14 +64,18 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -83,9 +83,11 @@ if (
|
||||
$file = isset($homepageMap[$_SERVER['HTTP_HOST']]) ? $homepageMap[$_SERVER['HTTP_HOST']] : $file;
|
||||
}
|
||||
|
||||
// Encode each part of the path individually, in order to support multibyte paths.
|
||||
// SiteTree.URLSegment and hence the static folder and filenames are stored in encoded form,
|
||||
// to avoid filesystem incompatibilities.
|
||||
$file = implode('/', array_map('rawurlencode', explode('/', $file)));
|
||||
// Find file by extension (either *.html or *.php)
|
||||
$file = preg_replace('/[^a-zA-Z0-9\/\-_]/si', '-', $file);
|
||||
|
||||
if (file_exists($cacheBaseDir . $cacheDir . $file . '.html')) {
|
||||
header('X-SilverStripe-Cache: hit at '.@date('r'));
|
||||
echo file_get_contents($cacheBaseDir . $cacheDir . $file . '.html');
|
||||
|
@ -116,10 +116,13 @@ class ConvertTest extends SapphireTest {
|
||||
* @todo test toASCII()
|
||||
*/
|
||||
function testRaw2URL() {
|
||||
$orig = URLSegmentFilter::$default_allow_multibyte;
|
||||
URLSegmentFilter::$default_allow_multibyte = false;
|
||||
$this->assertEquals('foo', Convert::raw2url('foo'));
|
||||
$this->assertEquals('foo-and-bar', Convert::raw2url('foo & bar'));
|
||||
$this->assertEquals('foo-and-bar', Convert::raw2url('foo & bar!'));
|
||||
$this->assertEquals('foos-bar-2', Convert::raw2url('foo\'s [bar] (2)'));
|
||||
URLSegmentFilter::$default_allow_multibyte = $orig;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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