|
| 1 | +--TEST-- |
| 2 | +Bug #69477 (ZipArchive::extractTo() truncates path segments ending with dot) |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +if(!extension_loaded('zip')) die('skip'); |
| 6 | +?> |
| 7 | +--FILE-- |
| 8 | +<?php |
| 9 | +include __DIR__ . '/utils.inc'; |
| 10 | +$dir = __DIR__ . '/bug69477'; |
| 11 | +if (file_exists($dir)) rmdir_rf($dir); |
| 12 | +mkdir($dir); |
| 13 | +$zipfile = $dir . '/abc.zip'; |
| 14 | + |
| 15 | +$archive = new ZipArchive(); |
| 16 | + |
| 17 | +if (!$archive->open($zipfile, ZipArchive::CREATE)) { |
| 18 | + exit('failed: unable to create archive'); |
| 19 | +} |
| 20 | + |
| 21 | +// (string) Entry path in the ZIP => (string) Expected actual target path |
| 22 | +$paths = [ |
| 23 | + '.a/b/c/file01.txt' => '.a/b/c/file01.txt', |
| 24 | + 'a./b/c/file02.txt' => 'a./b/c/file02.txt', |
| 25 | + 'a/.b/c/file03.txt' => 'a/.b/c/file03.txt', |
| 26 | + 'a/b./c/file04.txt' => 'a/b./c/file04.txt', |
| 27 | + 'a/b../c/file05.txt' => 'a/b../c/file05.txt', |
| 28 | + 'a/b.../c/file06.txt' => 'a/b.../c/file06.txt', |
| 29 | + 'a/..b/c/file07.txt' => 'a/..b/c/file07.txt', |
| 30 | + 'a/...b/c/file08.txt' => 'a/...b/c/file08.txt', |
| 31 | + 'a/../b./c./file09.txt' => 'b./c./file09.txt', |
| 32 | + '//../b./c./file10.txt' => 'b./c./file10.txt', |
| 33 | + '/../b./c./file11.txt' => 'b./c./file11.txt', |
| 34 | + 'C:/a./b./file12.txt' => 'a./b./file12.txt', |
| 35 | + 'a/b:/c/file13.txt' => 'c/file13.txt', |
| 36 | +]; |
| 37 | + |
| 38 | +foreach ($paths as $zippath => $realpath) { |
| 39 | + $archive->addFromString($zippath, $zippath . ' => ' . $realpath); |
| 40 | +} |
| 41 | + |
| 42 | +$archive->close(); |
| 43 | + |
| 44 | +$archive2 = new ZipArchive(); |
| 45 | + |
| 46 | +if (!$archive2->open($zipfile)) { |
| 47 | + exit('failed: unable to open archive2'); |
| 48 | +} |
| 49 | + |
| 50 | +$archive2->extractTo($dir); |
| 51 | +$archive2->close(); |
| 52 | + |
| 53 | +foreach ($paths as $zippath => $realpath) { |
| 54 | + if (!is_readable($dir . '/' . $realpath) || file_get_contents($dir . '/' . $realpath) !== $zippath . ' => ' . $realpath) { |
| 55 | + exit('failed: ' . $zippath); |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +echo 'ok'; |
| 60 | +?> |
| 61 | +--CLEAN-- |
| 62 | +<?php |
| 63 | +include __DIR__ . '/utils.inc'; |
| 64 | +$dir = __DIR__ . '/bug69477'; |
| 65 | +rmdir_rf($dir); |
| 66 | +?> |
| 67 | +--EXPECT-- |
| 68 | +ok |
0 commit comments