Skip to content

Commit

Permalink
Merge branch 'PHP-8.2' into PHP-8.3
Browse files Browse the repository at this point in the history
* PHP-8.2:
  NEWS
  NEWS
  fix GH-12661 (Inconsistency in ZipArchive::addGlob remove_path Option Behavior)
  • Loading branch information
remicollet committed Nov 14, 2023
2 parents 5c25742 + 2536cf7 commit 14f10ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/zip/php_zip.c
Expand Up @@ -1772,7 +1772,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
basename = php_basename(Z_STRVAL_P(zval_file), Z_STRLEN_P(zval_file), NULL, 0);
file_stripped = ZSTR_VAL(basename);
file_stripped_len = ZSTR_LEN(basename);
} else if (opts.remove_path && strstr(Z_STRVAL_P(zval_file), opts.remove_path) != NULL) {
} else if (opts.remove_path && !memcmp(Z_STRVAL_P(zval_file), opts.remove_path, opts.remove_path_len)) {
if (IS_SLASH(Z_STRVAL_P(zval_file)[opts.remove_path_len])) {
file_stripped = Z_STRVAL_P(zval_file) + opts.remove_path_len + 1;
file_stripped_len = Z_STRLEN_P(zval_file) - opts.remove_path_len - 1;
Expand Down
25 changes: 25 additions & 0 deletions ext/zip/tests/bug_gh12661.phpt
@@ -0,0 +1,25 @@
--TEST--
Bug GH-12661 (Inconsistency in ZipArchive::addGlob 'remove_path' Option Behavior)
--EXTENSIONS--
zip
--FILE--
<?php
include __DIR__ . '/utils.inc';

touch($file = __DIR__ . '/bug_gh12661.zip');

$zip = new ZipArchive();
$zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addGlob(__FILE__, 0, ['remove_path' => 'bug_']); // unchanged (bug is not a prefix)
$zip->addGlob(__FILE__, 0, ['remove_path' => dirname(__DIR__)]);
verify_entries($zip, [__FILE__, basename(__DIR__) . DIRECTORY_SEPARATOR . basename(__FILE__)]);
$zip->close();

?>
Done
--CLEAN--
<?php
unlink(__DIR__ . '/bug_gh12661.zip');
?>
--EXPECT--
Done

0 comments on commit 14f10ec

Please sign in to comment.