|
| 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 | + |
| 19 | +file_put_contents(__DIR__ . '/bug81211/foobar/file', 'this file should NOT be included in the archive!'); |
| 20 | +symlink(__DIR__ . '/bug81211/foobar/file', __DIR__ . '/bug81211/foo/symlink'); |
| 21 | + |
| 22 | +$archive = new PharData(__DIR__ . '/bug81211/archive.tar'); |
| 23 | +try { |
| 24 | + $archive->buildFromDirectory(__DIR__ . '/bug81211/foo'); |
| 25 | +} catch (UnexpectedValueException $ex) { |
| 26 | + echo $ex->getMessage(), PHP_EOL; |
| 27 | +} |
| 28 | +try { |
| 29 | + $archive->buildFromIterator(new RecursiveDirectoryIterator(__DIR__ . '/bug81211/foo', FilesystemIterator::SKIP_DOTS), __DIR__ . '/bug81211/foo'); |
| 30 | +} catch (UnexpectedValueException $ex) { |
| 31 | + echo $ex->getMessage(), PHP_EOL; |
| 32 | +} |
| 33 | +?> |
| 34 | +--CLEAN-- |
| 35 | +<?php |
| 36 | +@unlink(__DIR__ . '/bug81211/archive.tar'); |
| 37 | +@unlink(__DIR__ . '/bug81211/foo/symlink'); |
| 38 | +@unlink(__DIR__ . '/bug81211/foobar/file'); |
| 39 | +@rmdir(__DIR__ . '/bug81211/foo'); |
| 40 | +@rmdir(__DIR__ . '/bug81211/foobar'); |
| 41 | +@rmdir(__DIR__ . '/bug81211'); |
| 42 | +?> |
| 43 | +--EXPECTF-- |
| 44 | +Iterator RecursiveIteratorIterator returned a path "%s%ebug81211\foobar\file" that is not in the base directory "%s%ebug81211\foo" |
| 45 | +Iterator RecursiveDirectoryIterator returned a path "%s%ebug81211\foobar\file" that is not in the base directory "%s%ebug81211\foo" |
0 commit comments