bug54289.phpt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. --TEST--
  2. Bug #54289 Phar::extractTo() does not accept specific directories to be extracted
  3. --EXTENSIONS--
  4. phar
  5. --INI--
  6. phar.readonly = 0
  7. --FILE--
  8. <?php
  9. // put our test fixtures into a far
  10. $base = __DIR__.DIRECTORY_SEPARATOR.'bug54289'.DIRECTORY_SEPARATOR;
  11. $inDir = $base.'in';
  12. $phar = $base.'test.phar';
  13. $pharA = new Phar($phar);
  14. $pharA->buildFromDirectory($inDir);
  15. // we should be able to pull out a directory that's there, but none that share
  16. // the same prefix
  17. $outDir = $base.'out';
  18. $pharB = new Phar($phar);
  19. $pharB->extractTo($outDir, 'dirA/', true);
  20. var_dump(file_exists($outDir.DIRECTORY_SEPARATOR.'dirA'.DIRECTORY_SEPARATOR.'fileA'));
  21. var_dump(file_exists($outDir.DIRECTORY_SEPARATOR.'dirA'.DIRECTORY_SEPARATOR.'fileB'));
  22. var_dump(is_dir($outDir.DIRECTORY_SEPARATOR.'dirAB'));
  23. // should also not be able to pull out non-existent ones
  24. try {
  25. $pharB->extractTo($outDir, 'dirX/', true);
  26. echo 'failed to throw expected exception';
  27. } catch (PharException $ex) {
  28. }
  29. // should also not be able to pull out /, because paths are not "rooted" that way
  30. try {
  31. $pharB->extractTo($outDir, '/', true);
  32. echo 'failed to throw expected exception';
  33. } catch (PharException $ex) {
  34. }
  35. // should be able to do by array, too
  36. $pharB = new Phar($phar);
  37. $pharB->extractTo($outDir, [ 'dirA/', 'dirAB/' ], true);
  38. // but not an array with a bad member in it
  39. try {
  40. $pharB = new Phar($phar);
  41. $pharB->extractTo($outDir, [ 'dirA/', 'dirX/' ], true);
  42. echo 'failed to throw expected exception';
  43. } catch (PharException $ex) {
  44. }
  45. echo 'done';
  46. ?>
  47. --CLEAN--
  48. <?php
  49. $base = __DIR__.DIRECTORY_SEPARATOR.'bug54289'.DIRECTORY_SEPARATOR;
  50. $phar = $base.'test.phar';
  51. $outDir = $base.'out';
  52. unlink($phar);
  53. $iter = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(
  54. $outDir, \FilesystemIterator::SKIP_DOTS|\FilesystemIterator::UNIX_PATHS),
  55. \RecursiveIteratorIterator::CHILD_FIRST);
  56. foreach ($iter as $value) {
  57. $value->isFile() ? unlink($value) : rmdir($value);
  58. }
  59. ?>
  60. --EXPECT--
  61. bool(true)
  62. bool(true)
  63. bool(false)
  64. done