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