Skip to content

Commit c36ce04

Browse files
committed
Fix #70103: ZipArchive::addGlob ignores remove_all_path option
When the remove_all_path option is set, but no add_path option, remove_all_path is simply ignored. This patch fixes this.
1 parent f9744a3 commit c36ce04

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

ext/zip/php_zip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,8 +1691,8 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
16911691
entry_name = entry_name_buf;
16921692
entry_name_len = strlen(entry_name);
16931693
} else {
1694-
entry_name = Z_STRVAL_P(zval_file);
1695-
entry_name_len = Z_STRLEN_P(zval_file);
1694+
entry_name = file_stripped;
1695+
entry_name_len = file_stripped_len;
16961696
}
16971697
if (basename) {
16981698
zend_string_release(basename);

ext/zip/tests/bug70103.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Bug #70103 (ZipArchive::addGlob ignores remove_all_path option)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('zip')) die('skip zip support not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$dir = __DIR__ . '/bug70103';
10+
11+
mkdir($dir); chmod($dir, 0777);
12+
file_put_contents($dir . '/foo.txt', 'foo');
13+
14+
$zip = new ZipArchive();
15+
$zip->open($dir . '/test.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
16+
$zip->addGlob($dir . '/*.txt', GLOB_NOSORT, array('remove_all_path' => true));
17+
$zip->close();
18+
19+
$zip = new ZipArchive();
20+
$zip->open($dir . '/test.zip');
21+
var_dump($zip->numFiles);
22+
var_dump($zip->getNameIndex(0));
23+
$zip->close();
24+
?>
25+
--CLEAN--
26+
<?php
27+
$dir = __DIR__ . '/bug70103';
28+
unlink($dir . '/foo.txt');
29+
unlink($dir . '/test.zip');
30+
rmdir($dir);
31+
?>
32+
--EXPECT--
33+
int(1)
34+
string(7) "foo.txt"

0 commit comments

Comments
 (0)