summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2013-08-03 17:15:13 +0200
committerAndreas Gohr <andi@splitbrain.org>2013-08-03 17:19:54 +0200
commit0a57f27ea5c1a6d54627f6af15c516f18f44b229 (patch)
treef2d599ecdfb8b8273de057cbdf14f3871f573775 /inc
parenta614f02796c8b18f69a756beee638c1683ac7fc7 (diff)
downloadrpg-0a57f27ea5c1a6d54627f6af15c516f18f44b229.tar.gz
rpg-0a57f27ea5c1a6d54627f6af15c516f18f44b229.tar.bz2
fixed cleanPath bug in tar library FS#2802
This time the test case was correct and actually showed a bug in the tar library. The error occured only on the first build (directory build/0/) where the zero was stripped from the path name. I added unit tests to the cleanPath function and discovered another bug with handling relative directories. I rewrote the cleanPath() function and now it should finally work. Unit tests FTW!
Diffstat (limited to 'inc')
-rw-r--r--inc/Tar.class.php28
1 files changed, 11 insertions, 17 deletions
diff --git a/inc/Tar.class.php b/inc/Tar.class.php
index d1a38ea0e..bc87d7d29 100644
--- a/inc/Tar.class.php
+++ b/inc/Tar.class.php
@@ -568,29 +568,23 @@ class Tar {
}
/**
- * Cleans up a path and removes relative parts
+ * Cleans up a path and removes relative parts, also strips leading slashes
*
* @param string $p_dir
* @return string
*/
- protected function cleanPath($p_dir) {
- $r = '';
- if($p_dir) {
- $subf = explode("/", $p_dir);
-
- for($i = count($subf) - 1; $i >= 0; $i--) {
- if($subf[$i] == ".") {
- # do nothing
- } elseif($subf[$i] == "..") {
- $i--;
- } elseif(!$subf[$i] && $i != count($subf) - 1 && $i) {
- # do nothing
- } else {
- $r = $subf[$i].($i != (count($subf) - 1) ? "/".$r : "");
- }
+ public function cleanPath($path) {
+ $path=explode('/', $path);
+ $newpath=array();
+ foreach($path as $p) {
+ if ($p === '' || $p === '.') continue;
+ if ($p==='..') {
+ array_pop($newpath);
+ continue;
}
+ array_push($newpath, $p);
}
- return $r;
+ return trim(implode('/', $newpath), '/');
}
/**