From 4cce6296662a5d88dd4d0a6cbcdb53ee51e81d04 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 3 Mar 2011 15:41:01 +0000 Subject: [PATCH] * fixed handling of + char in VFS filenames (using egw_vfs::decodePath() instead of urldecode()) --- etemplate/inc/class.vfs_widget.inc.php | 16 +++++------ filemanager/inc/class.filemanager_ui.inc.php | 28 +++++++++---------- phpgwapi/inc/class.egw_link.inc.php | 6 ++-- phpgwapi/inc/class.egw_vfs.inc.php | 17 +++++++++-- .../class.filesystem_stream_wrapper.inc.php | 24 ++++++++-------- 5 files changed, 52 insertions(+), 39 deletions(-) diff --git a/etemplate/inc/class.vfs_widget.inc.php b/etemplate/inc/class.vfs_widget.inc.php index 2d159329ae..f4be2d3b3a 100644 --- a/etemplate/inc/class.vfs_widget.inc.php +++ b/etemplate/inc/class.vfs_widget.inc.php @@ -85,7 +85,7 @@ class vfs_widget { if (!$value || !($stat = egw_vfs::stat($value))) { - if ($value) $value = lang("File '%1' not found!",urldecode($value)); + if ($value) $value = lang("File '%1' not found!",egw_vfs::decodePath($value)); $cell = etemplate::empty_cell(); return true; // allow extra value; } @@ -208,7 +208,7 @@ class vfs_widget soetemplate::add_child($cell,$sep); unset($sep); } - $value['c'.$n] = $component !== '' ? urldecode($component) : '/'; + $value['c'.$n] = $component !== '' ? egw_vfs::decodePath($component) : '/'; $path .= ($path != '/' ? '/' : '').$component; // replace id's in /apps again with human readable titles $path_parts = explode('/',$path); @@ -271,7 +271,7 @@ class vfs_widget list($length,$maxLength,$allowPath) = $options = explode(',',$cell['size']); $preg = $allowPath ? '' : '/[^\\/]/'; // no slash '/' allowed, if not allowPath set $cell['size'] = "$length,$maxLength,$preg"; - $value = urldecode($value); + $value = egw_vfs::decodePath($value); $extension_data = array('type' => $type,'allowPath' => $allowPath); break; @@ -349,7 +349,7 @@ class vfs_widget list($span,$class) = explode(',',$cell['span'],2); $class .= ($class ? ' ' : '') . ($broken ? 'vfsIsBrokenLink' : 'vfsIsLink'); $cell['span'] = $span.','.$class; - $cell['label'] = ($broken ? lang('Broken link') : lang('Link')).': '.urldecode(egw_vfs::readlink($path)). + $cell['label'] = ($broken ? lang('Broken link') : lang('Link')).': '.egw_vfs::decodePath(egw_vfs::readlink($path)). (!$broken ? ' ('.$cell['label'].')' : ''); } break; @@ -371,7 +371,7 @@ class vfs_widget */ static function file_widget(&$value,$path,$name,$label=null) { - $value = empty($label) ? urldecode(egw_vfs::basename($path)) : lang($label); // display (translated) Label or filename (if label empty) + $value = empty($label) ? egw_vfs::decodePath(egw_vfs::basename($path)) : lang($label); // display (translated) Label or filename (if label empty) $vfs_link = etemplate::empty_cell('label',$name,array( 'size' => ','.egw_vfs::download_url($path).',,,_blank,,'.$path, @@ -478,7 +478,7 @@ class vfs_widget { if (!egw_vfs::unlink($extension_data['path'].$file)) { - etemplate::set_validation_error($name,lang('Error deleting %1!',urldecode($extension_data['path'].$file))); + etemplate::set_validation_error($name,lang('Error deleting %1!',egw_vfs::decodePath($extension_data['path'].$file))); } break; } @@ -486,7 +486,7 @@ class vfs_widget } elseif (!egw_vfs::unlink($extension_data['path'])) { - etemplate::set_validation_error($name,lang('Error deleting %1!',urldecode($extension_data['path']))); + etemplate::set_validation_error($name,lang('Error deleting %1!',egw_vfs::decodePath($extension_data['path']))); } $loop = true; return false; @@ -539,7 +539,7 @@ class vfs_widget } if (!egw_vfs::file_exists($dir = egw_vfs::dirname($path)) && !egw_vfs::mkdir($dir,null,STREAM_MKDIR_RECURSIVE)) { - etemplate::set_validation_error($name,lang('Error create parent directory %1!',urldecode($dir))); + etemplate::set_validation_error($name,lang('Error create parent directory %1!',egw_vfs::decodePath($dir))); return false; } if (!copy($tmp_name,egw_vfs::PREFIX.$path)) diff --git a/filemanager/inc/class.filemanager_ui.inc.php b/filemanager/inc/class.filemanager_ui.inc.php index ac910a9c38..02862507a1 100644 --- a/filemanager/inc/class.filemanager_ui.inc.php +++ b/filemanager/inc/class.filemanager_ui.inc.php @@ -154,7 +154,7 @@ class filemanager_ui } else { - $msg .= lang('The requested path %1 is not available.',urldecode($path)); + $msg .= lang('The requested path %1 is not available.',egw_vfs::decodePath($path)); } // reset lettersearch as it confuses users (they think the dir is empty) $content['nm']['searchletter'] = false; @@ -283,11 +283,11 @@ class filemanager_ui $abs_target = $target[0] == '/' ? $target : egw_vfs::concat($content['nm']['path'],$target); if (!egw_vfs::stat($abs_target)) { - $content['nm']['msg'] = lang('Link target %1 not found!',urldecode($abs_target)); + $content['nm']['msg'] = lang('Link target %1 not found!',egw_vfs::decodePath($abs_target)); break; } $content['nm']['msg'] = egw_vfs::symlink($target,$link) ? - lang('Symlink to %1 created.',$target) : lang('Error creating symlink to target %1!',urldecode($target)); + lang('Symlink to %1 created.',$target) : lang('Error creating symlink to target %1!',egw_vfs::decodePath($target)); break; case 'paste': $content['nm']['msg'] = self::action($clipboard_type.'_paste',$clipboard_files,$content['nm']['path']); @@ -322,7 +322,7 @@ class filemanager_ui if ($upload_success) { $content['nm']['msg'] = count($upload_success) == 1 && !$upload_failure ? lang('File successful uploaded.') : - lang('%1 successful uploaded.',urldecode(implode(', ',$upload_success))); + lang('%1 successful uploaded.',implode(', ',$upload_success)); } if ($upload_failure) { @@ -340,11 +340,11 @@ class filemanager_ui $dir_is_writable = egw_vfs::is_writable($content['nm']['path']); } $content['paste_tooltip'] = $clipboard_files ? '

'.lang('%1 the following files into current directory', - $clipboard_type=='copy'?lang('Copy'):lang('Move')).':
'.urldecode(implode('
',$clipboard_files)).'

' : ''; + $clipboard_type=='copy'?lang('Copy'):lang('Move')).':
'.egw_vfs::decodePath(implode('
',$clipboard_files)).'

' : ''; $content['linkpaste_tooltip'] = $clipboard_files ? '

'.lang('%1 the following files into current directory', - lang('link')).':
'.urldecode(implode('
',$clipboard_files)).'

' : ''; + lang('link')).':
'.egw_vfs::decodePath(implode('
',$clipboard_files)).'

' : ''; $content['mailpaste_tooltip'] = $clipboard_files ? '

'.lang('Mail files'). - ':
'.urldecode(implode('
',$clipboard_files)).'

' : ''; + ':
'.egw_vfs::decodePath(implode('
',$clipboard_files)).'

' : ''; $content['mailpaste_files'] = $clipboard_files; $content['upload_size'] = etemplate::max_upload_size_message(); //_debug_array($content); @@ -445,7 +445,7 @@ class filemanager_ui } else { - $response->addScript("if (!confirm('".addslashes(lang('Do you want to overwrite the existing file %1?',urldecode($path)))."')) document.getElementById('$id').value='';"); + $response->addScript("if (!confirm('".addslashes(lang('Do you want to overwrite the existing file %1?',egw_vfs::decodePath($path)))."')) document.getElementById('$id').value='';"); } } else @@ -642,7 +642,7 @@ class filemanager_ui if (preg_match('/^\/?(home|apps|)\/*$/',$path)) { $errs++; - return lang("Cautiously rejecting to remove folder '%1'!",urldecode($path)); + return lang("Cautiously rejecting to remove folder '%1'!",egw_vfs::decodePath($path)); } } // now we use find to loop through all files and dirs: (selected only contains dirs now) @@ -702,7 +702,7 @@ class filemanager_ui // an appropriate message egw::redirect_link('/index.php',array('menuaction'=>'filemanager.filemanager_ui.index', 'path' => self::get_home_dir(), - 'msg' => lang('The requested path %1 is not available.',urldecode($query['path'])), + 'msg' => lang('The requested path %1 is not available.',egw_vfs::decodePath($query['path'])), )); } $rows = $dir_is_writable = array(); @@ -788,7 +788,7 @@ class filemanager_ui } else { - $GLOBALS['egw_info']['flags']['app_header'] = lang('Filemanager').': '.urldecode($query['path']); + $GLOBALS['egw_info']['flags']['app_header'] = lang('Filemanager').': '.egw_vfs::decodePath($query['path']); } return egw_vfs::$find_total; } @@ -890,7 +890,7 @@ class filemanager_ui } if (egw_vfs::rename($path,$to)) { - $msg .= lang('Renamed %1 to %2.',urldecode(basename($path)),urldecode(basename($to))).' '; + $msg .= lang('Renamed %1 to %2.',egw_vfs::decodePath(basename($path)),egw_vfs::decodePath(basename($to))).' '; $content['old']['name'] = $content[$name]; $path = $to; $content['mime'] = mime_magic::filename2mime($path); // recheck mime type @@ -898,7 +898,7 @@ class filemanager_ui } else { - $msg .= lang('Rename of %1 to %2 failed!',urldecode(basename($path)),urldecode(basename($to))).' '; + $msg .= lang('Rename of %1 to %2 failed!',egw_vfs::decodePath(basename($path)),egw_vfs::decodePath(basename($to))).' '; if (egw_vfs::deny_script($to)) { $msg .= lang('You are NOT allowed to upload a script!').' '; @@ -1110,7 +1110,7 @@ class filemanager_ui } } $GLOBALS['egw_info']['flags']['java_script'] = "\n"; - $GLOBALS['egw_info']['flags']['app_header'] = lang('Preferences').' '.urldecode($path); + $GLOBALS['egw_info']['flags']['app_header'] = lang('Preferences').' '.egw_vfs::decodePath($path); $tpl->exec('filemanager.filemanager_ui.file',$content,$sel_options,$readonlys,$preserve,2); } diff --git a/phpgwapi/inc/class.egw_link.inc.php b/phpgwapi/inc/class.egw_link.inc.php index 9a74ea0ae3..94d0ecd0b8 100644 --- a/phpgwapi/inc/class.egw_link.inc.php +++ b/phpgwapi/inc/class.egw_link.inc.php @@ -61,7 +61,7 @@ * ), * 'edit_id' => 'app_id', * 'edit_popup' => '400x300', - * 'additional' => array( // allow one app to register sub-types, + * 'additional' => array( // allow one app to register sub-types, * 'app-sub' => array( // different from 'types' approach above * // every value defined above * ) @@ -659,7 +659,7 @@ class egw_link extends solink if (is_array($id) && $link) { $link = $id; - $title = $link['name']; + $title = egw_vfs::decodePath($link['name']); } else { @@ -672,7 +672,7 @@ class egw_link extends solink $title .= ': '.$link['type'] . ' '.egw_vfs::hsize($link['size']); }*/ if (self::DEBUG) echo '

'.__METHOD__."('$app','$id')='$title' (file)

\n"; - return urldecode($title); + return $title; } if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['title'])) { diff --git a/phpgwapi/inc/class.egw_vfs.inc.php b/phpgwapi/inc/class.egw_vfs.inc.php index 77fdd107d9..6cfd3892d9 100644 --- a/phpgwapi/inc/class.egw_vfs.inc.php +++ b/phpgwapi/inc/class.egw_vfs.inc.php @@ -1450,7 +1450,7 @@ class egw_vfs extends vfs_stream_wrapper * * Not all chars get encoded, slashes '/' are silently removed! * - * To reverse the encoding, eg. to display a filename to the user, you can use urldecode() + * To reverse the encoding, eg. to display a filename to the user, you have to use egw_vfs::decodePath() * * @param string|array $component * @return string|array @@ -1463,7 +1463,7 @@ class egw_vfs extends vfs_stream_wrapper /** * Encode a path: replacing certain chars with their urlencoded counterparts * - * To reverse the encoding, eg. to display a filename to the user, you can use urldecode() + * To reverse the encoding, eg. to display a filename to the user, you have to use egw_vfs::decodePath() * * @param string $path * @return string @@ -1473,6 +1473,19 @@ class egw_vfs extends vfs_stream_wrapper return implode('/',self::encodePathComponent(explode('/',$path))); } + /** + * Decode a path: rawurldecode(): mostly urldecode(), but do NOT decode '+', as we're NOT encoding it! + * + * Used eg. to translate a path for displaying to the User. + * + * @param string $path + * @return string + */ + static public function decodePath($path) + { + return rawurldecode($path); + } + /** * Initialise our static vars */ diff --git a/phpgwapi/inc/class.filesystem_stream_wrapper.inc.php b/phpgwapi/inc/class.filesystem_stream_wrapper.inc.php index c01706fa25..b85f6b8e10 100644 --- a/phpgwapi/inc/class.filesystem_stream_wrapper.inc.php +++ b/phpgwapi/inc/class.filesystem_stream_wrapper.inc.php @@ -153,7 +153,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper } // open the "real" file - if (!($this->opened_stream = fopen($path=urldecode(parse_url($url,PHP_URL_PATH)),$mode,$options))) + if (!($this->opened_stream = fopen($path=egw_vfs::decodePath(parse_url($url,PHP_URL_PATH)),$mode,$options))) { if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) fopen('$path','$mode',$options) returned false!"); return false; @@ -295,7 +295,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper */ static function unlink ( $url ) { - $path = urldecode(parse_url($url,PHP_URL_PATH)); + $path = egw_vfs::decodePath(parse_url($url,PHP_URL_PATH)); // check access rights (file need to exist and directory need to be writable if (!file_exists($path) || is_dir($path) || !egw_vfs::check_access(egw_vfs::dirname($url),egw_vfs::WRITABLE)) @@ -355,7 +355,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!"); return false; } - return rename(urldecode($from['path']),urldecode($to['path'])); + return rename(egw_vfs::decodePath($from['path']),egw_vfs::decodePath($to['path'])); } /** @@ -371,7 +371,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper */ static function mkdir ( $url, $mode, $options ) { - $path = urldecode(parse_url($url,PHP_URL_PATH)); + $path = egw_vfs::decodePath(parse_url($url,PHP_URL_PATH)); $recursive = (bool)($options & STREAM_MKDIR_RECURSIVE); // find the real parent (might be more then one level if $recursive!) @@ -403,7 +403,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper */ static function rmdir ( $url, $options ) { - $path = urldecode(parse_url($url,PHP_URL_PATH)); + $path = egw_vfs::decodePath(parse_url($url,PHP_URL_PATH)); $parent = dirname($path); // check access rights (in real filesystem AND by mount perms) @@ -425,7 +425,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper */ static function touch($url,$time=null,$atime=null) { - $path = urldecode(parse_url($url,PHP_URL_PATH)); + $path = egw_vfs::decodePath(parse_url($url,PHP_URL_PATH)); $parent = dirname($path); // check access rights (in real filesystem AND by mount perms) @@ -492,7 +492,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper $this->opened_dir = null; - $path = urldecode(parse_url($this->opened_dir_url = $url,PHP_URL_PATH)); + $path = egw_vfs::decodePath(parse_url($this->opened_dir_url = $url,PHP_URL_PATH)); // ToDo: check access rights @@ -533,7 +533,7 @@ class filesystem_stream_wrapper implements iface_stream_wrapper static function url_stat ( $url, $flags ) { $parts = parse_url($url); - $path = urldecode($parts['path']); + $path = egw_vfs::decodePath($parts['path']); $stat = @stat($path); // suppressed the stat failed warnings @@ -733,20 +733,20 @@ class filesystem_stream_wrapper implements iface_stream_wrapper list(,$query) = explode('?',$url,2); parse_str($query,$get); if (empty($get['url'])) return false; // no download url given for this mount-point - + if (!($mount_url = egw_vfs::mount_url($url))) return false; // no mount url found, should not happen list($mount_url) = explode('?',$mount_url); - + list($url,$query) = explode('?',$url,2); $relpath = substr($url,strlen($mount_url)); - + $download_url = egw_vfs::concat($get['url'],$relpath); if ($download_url[0] == '/') { $download_url = ($_SERVER['HTTPS'] ? 'https://' : 'http://'). $_SERVER['HTTP_HOST'].$download_url; } - + //die(__METHOD__."('$url') --> relpath = $relpath --> $download_url"); return $download_url; }