diff --git a/src/Compress/Zip.php b/src/Compress/Zip.php index 81403534..5a6f01a0 100644 --- a/src/Compress/Zip.php +++ b/src/Compress/Zip.php @@ -184,13 +184,12 @@ public function compress($content) */ public function decompress($content) { - $archive = $this->getArchive(); + $archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, realpath($content)); if (empty($archive) || !file_exists($archive)) { throw new Exception\RuntimeException('ZIP Archive not found'); } - $archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, realpath($content)); $zip = new ZipArchive(); $res = $zip->open($archive); diff --git a/test/Compress/ZipTest.php b/test/Compress/ZipTest.php index fe9c87c9..10a55978 100644 --- a/test/Compress/ZipTest.php +++ b/test/Compress/ZipTest.php @@ -297,4 +297,36 @@ public function testDecompressWillThrowExceptionWhenDecompressingWithNoTarget() $content = file_get_contents($this->tmp . '/_compress'); $this->assertEquals('compress me', $content); } + + /** + * @group 6026 + * + * @covers \Zend\Filter\Compress\Zip::decompress + */ + public function testDecompressWhenNoArchieveInClass() + { + if (!constant('TESTS_ZEND_FILTER_COMPRESS_ZIP_ENABLED')) { + $this->markTestSkipped('ZIP compression tests are currently disabled'); + } + + $filter = new ZipCompression( + array( + 'archive' => $this->tmp . '/compressed.zip', + 'target' => $this->tmp . '/_compress' + ) + ); + + $content = $filter->compress('compress me'); + $this->assertEquals($this->tmp . DIRECTORY_SEPARATOR . 'compressed.zip', $content); + + $filter = new ZipCompression( + array( + 'target' => $this->tmp . '/_compress' + ) + ); + $content = $filter->decompress($content); + $this->assertEquals($this->tmp . DIRECTORY_SEPARATOR, $content); + $content = file_get_contents($this->tmp . '/_compress'); + $this->assertEquals('compress me', $content); + } }