summaryrefslogtreecommitdiff
path: root/_test
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 /_test
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 '_test')
-rw-r--r--_test/tests/inc/tar.test.php23
1 files changed, 22 insertions, 1 deletions
diff --git a/_test/tests/inc/tar.test.php b/_test/tests/inc/tar.test.php
index 9801ca1e0..417f1a853 100644
--- a/_test/tests/inc/tar.test.php
+++ b/_test/tests/inc/tar.test.php
@@ -58,6 +58,8 @@ class Tar_TestCase extends DokuWikiTest {
$tar->addData('another/testdata3.txt', 'testcontent3');
$tar->close();
+copy ($tmp, '/tmp/test.tar');
+
$this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number
$data = file_get_contents($tmp);
@@ -66,7 +68,7 @@ class Tar_TestCase extends DokuWikiTest {
$this->assertTrue(strpos($data, 'testcontent3') !== false, 'Content in TAR');
// fullpath might be too long to be stored as full path FS#2802
- $this->assertTrue(strpos($data, "$tdir") !== false, 'Path in TAR');
+ $this->assertTrue(strpos($data, "$tdir") !== false, "Path in TAR '$tdir'");
$this->assertTrue(strpos($data, "testdata1.txt") !== false, 'File in TAR');
$this->assertTrue(strpos($data, 'noway/testdata2.txt') !== false, 'Path in TAR');
@@ -396,4 +398,23 @@ class Tar_TestCase extends DokuWikiTest {
$this->assertEquals(512*4, strlen($file)); // 1 header block + data block + 2 footer blocks
}
+
+
+ public function test_cleanPath(){
+ $tar = new Tar();
+ $tests = array (
+ '/foo/bar' => 'foo/bar',
+ '/foo/bar/' => 'foo/bar',
+ 'foo//bar' => 'foo/bar',
+ 'foo/0/bar' => 'foo/0/bar',
+ 'foo/../bar' => 'bar',
+ 'foo/bang/bang/../../bar' => 'foo/bar',
+ 'foo/../../bar' => 'bar',
+ 'foo/.././../bar' => 'bar',
+ );
+
+ foreach($tests as $in => $out){
+ $this->assertEquals($out, $tar->cleanPath($in), "Input: $in");
+ }
+ }
}