Skip to content

Commit 1db0569

Browse files
committed
Merge branch 'PHP-7.1'
* PHP-7.1: Fix #70103: ZipArchive::addGlob ignores remove_all_path option news entry for PR #1430
2 parents a972143 + 3f89aec commit 1db0569

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,7 @@ PHP NEWS
103103
- XMLRPC:
104104
. Use Zend MM for allocation in bundled libxmlrpc (Joe)
105105

106+
- ZIP:
107+
. Fixed bug #70103 (ZipArchive::addGlob ignores remove_all_path option). (cmb)
108+
106109
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>

ext/zip/php_zip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,8 +1704,8 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
17041704
entry_name = entry_name_buf;
17051705
entry_name_len = strlen(entry_name);
17061706
} else {
1707-
entry_name = Z_STRVAL_P(zval_file);
1708-
entry_name_len = Z_STRLEN_P(zval_file);
1707+
entry_name = file_stripped;
1708+
entry_name_len = file_stripped_len;
17091709
}
17101710
if (basename) {
17111711
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)