summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--UPGRADING7
-rw-r--r--ext/zip/php_zip.c5
-rw-r--r--ext/zip/tests/bug72374.phpt32
-rw-r--r--ext/zip/tests/oo_addpattern.phpt6
5 files changed, 48 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index c290ef0cd5..1692bd9b87 100644
--- a/NEWS
+++ b/NEWS
@@ -68,4 +68,7 @@ PHP NEWS
. Changed functions to accept/return XMKWriter objects instead of resources.
(cmb)
+- Zip:
+ . Fixed bug #72374 (remove_path strips first char of filename). (tyage)
+
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
diff --git a/UPGRADING b/UPGRADING
index 99c41d8adb..302daa57ec 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -280,6 +280,13 @@ PHP 8.0 UPGRADE NOTES
. The XMLWriter functions now accept and return, respectively, XMLWriter
objects instead of resources.
+- Zip:
+ . The remove_path option of ZipArchive::addGlob() and ::addPattern() is now
+ treated as arbitrary string prefix (for consistency with the add_path
+ option), whereas formerly it was treated as directory name. This means that
+ if no trailing directory separator is given, the following character is
+ no longer stripped from the filename.
+
- Zlib:
. gzgetss() has been removed.
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index cba217f1de..d30ad8747f 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -1602,6 +1602,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
size_t real_len = strlen(remove_path);
if ((real_len > 1) && ((remove_path[real_len - 1] == '/') || (remove_path[real_len - 1] == '\\'))) {
remove_path[real_len - 1] = '\0';
+ remove_path_len -= 1;
}
}
@@ -1627,8 +1628,8 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
file_stripped = ZSTR_VAL(basename);
file_stripped_len = ZSTR_LEN(basename);
} else if (remove_path && strstr(Z_STRVAL_P(zval_file), remove_path) != NULL) {
- file_stripped = Z_STRVAL_P(zval_file) + remove_path_len + 1;
- file_stripped_len = Z_STRLEN_P(zval_file) - remove_path_len - 1;
+ file_stripped = Z_STRVAL_P(zval_file) + remove_path_len;
+ file_stripped_len = Z_STRLEN_P(zval_file) - remove_path_len;
} else {
file_stripped = Z_STRVAL_P(zval_file);
file_stripped_len = Z_STRLEN_P(zval_file);
diff --git a/ext/zip/tests/bug72374.phpt b/ext/zip/tests/bug72374.phpt
new file mode 100644
index 0000000000..b214be3eaf
--- /dev/null
+++ b/ext/zip/tests/bug72374.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Bug #72374 (ZipArchive::addGlob remove_path option strips first char of filename)
+--SKIPIF--
+<?php
+if(!extension_loaded('zip')) die('skip');
+?>
+--FILE--
+<?php
+$dirname = dirname(__FILE__) . '/';
+include $dirname . 'utils.inc';
+
+$dirname = $dirname . 'bug72374/';
+mkdir($dirname);
+$file = $dirname . 'some-foo.txt';
+touch($file);
+
+$zip = new ZipArchive();
+$zip->open($dirname . 'test.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
+$zip->addGlob($file, 0, array('remove_path' => $dirname . 'some-'));
+$zip->addGlob($file, 0, array('remove_path' => $dirname));
+verify_entries($zip, ['foo.txt', '/some-foo.txt']);
+$zip->close();
+?>
+--CLEAN--
+<?php
+$dirname = dirname(__FILE__) . '/';
+include $dirname . 'utils.inc';
+
+$dirname = $dirname . 'bug72374/';
+rmdir_rf($dirname);
+?>
+--EXPECT--
diff --git a/ext/zip/tests/oo_addpattern.phpt b/ext/zip/tests/oo_addpattern.phpt
index fe1a57368d..19453bee49 100644
--- a/ext/zip/tests/oo_addpattern.phpt
+++ b/ext/zip/tests/oo_addpattern.phpt
@@ -25,7 +25,7 @@ if (!$zip->open($file)) {
exit('failed');
}
$dir = realpath($dirname);
-$options = array('add_path' => 'baz/', 'remove_path' => $dir);
+$options = array('add_path' => 'baz', 'remove_path' => $dir);
if (!$zip->addPattern('/\.txt$/', $dir, $options)) {
echo "failed\n";
}
@@ -35,8 +35,8 @@ if ($zip->status == ZIPARCHIVE::ER_OK) {
"foobar/",
"foobar/baz",
"entry1.txt",
- "baz/foo.txt",
- "baz/bar.txt"
+ "baz" . DIRECTORY_SEPARATOR . "foo.txt",
+ "baz" . DIRECTORY_SEPARATOR . "bar.txt"
])) {
echo "failed\n";
} else {