use full url-encoding for all clients as required by most clients and RFC

This commit is contained in:
Ralf Becker 2018-11-22 18:13:22 +08:00
parent 630c340ce8
commit dd8e9c6269

View File

@ -2692,43 +2692,20 @@ class HTTP_WebDAV_Server
} }
/** /**
* private minimalistic version of PHP urlencode() * private URL encoding
* *
* only blanks, percent and XML special chars must be encoded here * We use now full url-encoding as required by WebDAV RFC and many clients.
* full urlencode() encoding confuses some clients ... * Formerly HTTP_WebDAV_Server used to encode only: " %&<>+"
* *
* @param string URL to encode * @param string URL to encode
* @return string encoded URL * @return string encoded URL
* @todo check if other not explicitly named user-agents are happy with full url-encoding too and we can make it the default
*/ */
public static function _urlencode($url) public static function _urlencode($url)
{ {
// cadaver (and probably all neon using agents) need a more complete url encoding return strtr(rawurlencode($url),array(
// otherwise special chars like "$,()'" in filenames do NOT work '%2F' => '/',
if (strpos($_SERVER['HTTP_USER_AGENT'],'neon') !== false || '%3A' => ':',
// old netdrive does NOT use a User-Agent, but requires full urlencoding for non-ascii chars (eg. German Umlauts) ));
!isset($_SERVER['HTTP_USER_AGENT']) ||
// current netdrive uses "NetDrive 2.5.8" as user-agent
stripos($_SERVER['HTTP_USER_AGENT'],'NetDrive') !== false ||
// Cyberduck or Mountain Duck WebDAV clients
stripos($_SERVER['HTTP_USER_AGENT'],'Cyberduck') !== false ||
stripos($_SERVER['HTTP_USER_AGENT'],'Mountain Duck') !== false ||
// OS X Finder (WebDAVFS/3.0.0 (03008000) Darwin/14.3.0 (x86_64))
stripos($_SERVER['HTTP_USER_AGENT'],'WebDAVFS') !== false && stripos($_SERVER['HTTP_USER_AGENT'],'Darwin'))
{
return strtr(rawurlencode($url),array(
'%2F' => '/',
'%3A' => ':',
));
}
//error_log( __METHOD__."\n" .print_r($url,true));
return strtr($url, array(' ' => '%20',
'%' => '%25',
'&' => '%26',
'<' => '%3C',
'>' => '%3E',
'+' => '%2B',
));
} }
/** /**