bug81211.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. Bug #81211 (Symlinks are followed when creating PHAR archive)
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded('phar')) die('skip phar extension is not available');
  6. if (PHP_OS_FAMILY === 'Windows') {
  7. if (false === include __DIR__ . '/../../standard/tests/file/windows_links/common.inc') {
  8. die('skip windows_links/common.inc is not available');
  9. }
  10. skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
  11. }
  12. ?>
  13. --FILE--
  14. <?php
  15. mkdir(__DIR__ . '/bug81211');
  16. mkdir(__DIR__ . '/bug81211/foobar');
  17. mkdir(__DIR__ . '/bug81211/foo');
  18. file_put_contents(__DIR__ . '/bug81211/foobar/file', 'this file should NOT be included in the archive!');
  19. symlink(__DIR__ . '/bug81211/foobar/file', __DIR__ . '/bug81211/foo/symlink');
  20. $archive = new PharData(__DIR__ . '/bug81211/archive.tar');
  21. try {
  22. $archive->buildFromDirectory(__DIR__ . '/bug81211/foo');
  23. } catch (UnexpectedValueException $ex) {
  24. echo $ex->getMessage(), PHP_EOL;
  25. }
  26. try {
  27. $archive->buildFromIterator(new RecursiveDirectoryIterator(__DIR__ . '/bug81211/foo', FilesystemIterator::SKIP_DOTS), __DIR__ . '/bug81211/foo');
  28. } catch (UnexpectedValueException $ex) {
  29. echo $ex->getMessage(), PHP_EOL;
  30. }
  31. ?>
  32. --CLEAN--
  33. <?php
  34. @unlink(__DIR__ . '/bug81211/archive.tar');
  35. @unlink(__DIR__ . '/bug81211/foo/symlink');
  36. @unlink(__DIR__ . '/bug81211/foobar/file');
  37. @rmdir(__DIR__ . '/bug81211/foo');
  38. @rmdir(__DIR__ . '/bug81211/foobar');
  39. @rmdir(__DIR__ . '/bug81211');
  40. ?>
  41. --EXPECTF--
  42. Iterator RecursiveIteratorIterator returned a path "%s%ebug81211%efoobar%efile" that is not in the base directory "%s%ebug81211%efoo"
  43. Iterator RecursiveDirectoryIterator returned a path "%s%ebug81211%efoobar%efile" that is not in the base directory "%s%ebug81211%efoo"