Skip to content

Commit ddb887f

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: NEWS fix GH-12661 (Inconsistency in ZipArchive::addGlob remove_path Option Behavior)
2 parents 86c7d3e + 0b5824e commit ddb887f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

ext/zip/php_zip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
17631763
basename = php_basename(Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file), NULL, 0);
17641764
file_stripped = ZSTR_VAL(basename);
17651765
file_stripped_len = ZSTR_LEN(basename);
1766-
} else if (opts.remove_path && strstr(Z_STRVAL_P(zval_file), opts.remove_path) != NULL) {
1766+
} else if (opts.remove_path && !memcmp(Z_STRVAL_P(zval_file), opts.remove_path, opts.remove_path_len)) {
17671767
if (IS_SLASH(Z_STRVAL_P(zval_file)[opts.remove_path_len])) {
17681768
file_stripped = Z_STRVAL_P(zval_file) + opts.remove_path_len + 1;
17691769
file_stripped_len = Z_STRLEN_P(zval_file) - opts.remove_path_len - 1;

ext/zip/tests/bug_gh12661.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug GH-12661 (Inconsistency in ZipArchive::addGlob 'remove_path' Option Behavior)
3+
--EXTENSIONS--
4+
zip
5+
--FILE--
6+
<?php
7+
include __DIR__ . '/utils.inc';
8+
9+
touch($file = __DIR__ . '/bug_gh12661.zip');
10+
11+
$zip = new ZipArchive();
12+
$zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
13+
$zip->addGlob(__FILE__, 0, ['remove_path' => 'bug_']); // unchanged (bug is not a prefix)
14+
$zip->addGlob(__FILE__, 0, ['remove_path' => dirname(__DIR__)]);
15+
verify_entries($zip, [__FILE__, basename(__DIR__) . DIRECTORY_SEPARATOR . basename(__FILE__)]);
16+
$zip->close();
17+
18+
?>
19+
Done
20+
--CLEAN--
21+
<?php
22+
unlink(__DIR__ . '/bug_gh12661.zip');
23+
?>
24+
--EXPECT--
25+
Done

0 commit comments

Comments
 (0)