From 73641a03d5b4defc9af6a838ff614a7a6ca716cf Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Wed, 20 Jan 2010 22:33:53 +0100 Subject: [PATCH] Fixed issues 368 and 354, access to files with special characters. --- src/IDF/Scm.php | 8 ++++++++ src/IDF/Scm/Git.php | 1 + src/IDF/Scm/Mercurial.php | 6 ++++-- src/IDF/Scm/Svn.php | 19 +++++++------------ src/IDF/Views/Source.php | 3 ++- src/IDF/templates/idf/source/git/tree.html | 2 +- .../templates/idf/source/mercurial/file.html | 2 +- .../templates/idf/source/mercurial/tree.html | 2 +- src/IDF/templates/idf/source/svn/file.html | 2 +- src/IDF/templates/idf/source/svn/tree.html | 2 +- 10 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/IDF/Scm.php b/src/IDF/Scm.php index 1483615..9cbfb0d 100644 --- a/src/IDF/Scm.php +++ b/src/IDF/Scm.php @@ -371,5 +371,13 @@ class IDF_Scm } } } + + /** + * Given a path, encode everything but the / + */ + public static function smartEncode($path) + { + return str_replace('%2F', '/', rawurlencode($path)); + } } diff --git a/src/IDF/Scm/Git.php b/src/IDF/Scm/Git.php index add57a1..e796ed5 100644 --- a/src/IDF/Scm/Git.php +++ b/src/IDF/Scm/Git.php @@ -233,6 +233,7 @@ class IDF_Scm_Git extends IDF_Scm $file->author = 'Unknown'; } $file->fullpath = ($folder) ? $folder.'/'.$file->file : $file->file; + $file->efullpath = self::smartEncode($file->fullpath); if ($file->type == 'commit') { // We have a submodule $file = $this->getSubmodule($file, $commit); diff --git a/src/IDF/Scm/Mercurial.php b/src/IDF/Scm/Mercurial.php index 4ea690c..5400257 100644 --- a/src/IDF/Scm/Mercurial.php +++ b/src/IDF/Scm/Mercurial.php @@ -187,9 +187,11 @@ class IDF_Scm_Mercurial extends IDF_Scm continue; } } + $fullpath = ($folder) ? $folder.'/'.$file : $file; + $efullpath = self::smartEncode($fullpath); $res[] = (object) array('perm' => $perm, 'type' => $type, - 'hash' => $hash, 'fullpath' => ($folder) ? $folder.'/'.$file : $file, - 'file' => $file); + 'hash' => $hash, 'fullpath' => $fullpath, + 'efullpath' => $efullpath, 'file' => $file); } return $res; } diff --git a/src/IDF/Scm/Svn.php b/src/IDF/Scm/Svn.php index c15caaa..503fddf 100644 --- a/src/IDF/Scm/Svn.php +++ b/src/IDF/Scm/Svn.php @@ -169,7 +169,7 @@ class IDF_Scm_Svn extends IDF_Scm $cmd = sprintf(Pluf::f('svn_path', 'svn').' info --xml --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), - escapeshellarg($this->repo.'/'.self::urlencode($path)), + escapeshellarg($this->repo.'/'.self::smartEncode($path)), escapeshellarg($rev)); $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; $xmlInfo = shell_exec($cmd); @@ -196,7 +196,7 @@ class IDF_Scm_Svn extends IDF_Scm $cmd = sprintf(Pluf::f('svn_path', 'svn').' ls --xml --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), - escapeshellarg($this->repo.'/'.self::urlencode($folder)), + escapeshellarg($this->repo.'/'.self::smartEncode($folder)), escapeshellarg($commit)); $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; $xml = simplexml_load_string(shell_exec($cmd)); @@ -207,6 +207,7 @@ class IDF_Scm_Svn extends IDF_Scm $file['type'] = $this->assoc[(string) $entry['kind']]; $file['file'] = (string) $entry->name; $file['fullpath'] = $folder.((string) $entry->name); + $file['efullpath'] = self::smartEncode($file['fullpath']); $file['date'] = gmdate('Y-m-d H:i:s', strtotime((string) $entry->commit->date)); $file['rev'] = (string) $entry->commit['revision']; @@ -253,7 +254,7 @@ class IDF_Scm_Svn extends IDF_Scm $cmd = sprintf(Pluf::f('svn_path', 'svn').' info --xml --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), - escapeshellarg($this->repo.'/'.self::urlencode($filename)), + escapeshellarg($this->repo.'/'.self::smartEncode($filename)), escapeshellarg($rev)); $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; $xml = simplexml_load_string(shell_exec($cmd)); @@ -280,7 +281,7 @@ class IDF_Scm_Svn extends IDF_Scm $cmd = sprintf(Pluf::f('svn_path', 'svn').' cat --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), - escapeshellarg($this->repo.'/'.self::urlencode($def->fullpath)), + escapeshellarg($this->repo.'/'.self::smartEncode($def->fullpath)), escapeshellarg($def->rev)); $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; return ($cmd_only) ? $cmd : shell_exec($cmd); @@ -498,7 +499,7 @@ class IDF_Scm_Svn extends IDF_Scm $cmd = sprintf(Pluf::f('svn_path', 'svn').' proplist --xml --username=%s --password=%s %s@%s', escapeshellarg($this->username), escapeshellarg($this->password), - escapeshellarg($this->repo.'/'.self::urlencode($path)), + escapeshellarg($this->repo.'/'.self::smartEncode($path)), escapeshellarg($rev)); $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; $xmlProps = shell_exec($cmd); @@ -534,7 +535,7 @@ class IDF_Scm_Svn extends IDF_Scm escapeshellarg($property), escapeshellarg($this->username), escapeshellarg($this->password), - escapeshellarg($this->repo.'/'.self::urlencode($path)), + escapeshellarg($this->repo.'/'.self::smartEncode($path)), escapeshellarg($rev)); $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; $xmlProp = shell_exec($cmd); @@ -565,11 +566,5 @@ class IDF_Scm_Svn extends IDF_Scm $xml = simplexml_load_string($xmlInfo); return (string) $xml->entry->commit['revision']; } - - - public static function urlencode($string) - { - return str_replace('%2F', '/', urlencode($string)); - } } diff --git a/src/IDF/Views/Source.php b/src/IDF/Views/Source.php index 70b2874..1251b59 100644 --- a/src/IDF/Views/Source.php +++ b/src/IDF/Views/Source.php @@ -267,7 +267,7 @@ class IDF_Views_Source $stack = ''; $i = 0; foreach ($elts as $elt) { - $stack .= ($i==0) ? $elt : '/'.$elt; + $stack .= ($i==0) ? rawurlencode($elt) : '/'.rawurlencode($elt); $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::tree', array($project->shortname, $commit, $stack)); @@ -378,6 +378,7 @@ class IDF_Views_Source 'commit' => $commit, 'cobject' => $cobject, 'fullpath' => $request_file, + 'efullpath' => IDF_Scm::smartEncode($request_file), 'base' => $request_file_info->file, 'prev' => $previous, 'tree_in' => $in_branches, diff --git a/src/IDF/templates/idf/source/git/tree.html b/src/IDF/templates/idf/source/git/tree.html index 200907c..859a249 100644 --- a/src/IDF/templates/idf/source/git/tree.html +++ b/src/IDF/templates/idf/source/git/tree.html @@ -28,7 +28,7 @@ {/if} {foreach $files as $file} -{aurl 'url', 'IDF_Views_Source::tree', array($project.shortname, $commit, $file.fullpath)} +{aurl 'url', 'IDF_Views_Source::tree', array($project.shortname, $commit, $file.efullpath)} {$file.type} {if $file.type != 'extern'} diff --git a/src/IDF/templates/idf/source/mercurial/file.html b/src/IDF/templates/idf/source/mercurial/file.html index 50c9bba..c2e2968 100644 --- a/src/IDF/templates/idf/source/mercurial/file.html +++ b/src/IDF/templates/idf/source/mercurial/file.html @@ -18,7 +18,7 @@ {$file} -{aurl 'url', 'IDF_Views_Source::getFile', array($project.shortname, $commit, $fullpath)} +{aurl 'url', 'IDF_Views_Source::getFile', array($project.shortname, $commit, $efullpath)}

{trans 'Archive'} {trans 'Download this file'}

{/block} diff --git a/src/IDF/templates/idf/source/mercurial/tree.html b/src/IDF/templates/idf/source/mercurial/tree.html index 98a3990..b5880cf 100644 --- a/src/IDF/templates/idf/source/mercurial/tree.html +++ b/src/IDF/templates/idf/source/mercurial/tree.html @@ -28,7 +28,7 @@ {/if} {foreach $files as $file} -{aurl 'url', 'IDF_Views_Source::tree', array($project.shortname, $commit, $file.fullpath)} +{aurl 'url', 'IDF_Views_Source::tree', array($project.shortname, $commit, $file.efullpath)} {$file.type} {$file.file} diff --git a/src/IDF/templates/idf/source/svn/file.html b/src/IDF/templates/idf/source/svn/file.html index 427bfd4..5ed8114 100644 --- a/src/IDF/templates/idf/source/svn/file.html +++ b/src/IDF/templates/idf/source/svn/file.html @@ -28,7 +28,7 @@ {$file} -{aurl 'url', 'IDF_Views_Source::getFile', array($project.shortname, $commit, $fullpath)} +{aurl 'url', 'IDF_Views_Source::getFile', array($project.shortname, $commit, $efullpath)}

{trans 'Archive'} {trans 'Download this file'}

{/block} diff --git a/src/IDF/templates/idf/source/svn/tree.html b/src/IDF/templates/idf/source/svn/tree.html index 93c9b89..d9a1e29 100644 --- a/src/IDF/templates/idf/source/svn/tree.html +++ b/src/IDF/templates/idf/source/svn/tree.html @@ -40,7 +40,7 @@ {/if} {foreach $files as $file} - {aurl 'url', 'IDF_Views_Source::tree', array($project.shortname, $commit, $file.fullpath)} + {aurl 'url', 'IDF_Views_Source::tree', array($project.shortname, $commit, $file.efullpath)} {$file.type}