xref: /PHP-7.3/ext/phar/tests/bug81211.phpt (revision b815645a)
1--TEST--
2Bug #81211 (Symlinks are followed when creating PHAR archive)
3--SKIPIF--
4<?php
5if (!extension_loaded('phar')) die('skip phar extension is not available');
6if (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
15mkdir(__DIR__ . '/bug81211');
16mkdir(__DIR__ . '/bug81211/foobar');
17mkdir(__DIR__ . '/bug81211/foo');
18
19file_put_contents(__DIR__ . '/bug81211/foobar/file', 'this file should NOT be included in the archive!');
20symlink(__DIR__ . '/bug81211/foobar/file', __DIR__ . '/bug81211/foo/symlink');
21
22$archive = new PharData(__DIR__ . '/bug81211/archive.tar');
23try {
24    $archive->buildFromDirectory(__DIR__ . '/bug81211/foo');
25} catch (UnexpectedValueException $ex) {
26    echo $ex->getMessage(), PHP_EOL;
27}
28try {
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--
44Iterator RecursiveIteratorIterator returned a path "%s%ebug81211%efoobar%efile" that is not in the base directory "%s%ebug81211%efoo"
45Iterator RecursiveDirectoryIterator returned a path "%s%ebug81211%efoobar%efile" that is not in the base directory "%s%ebug81211%efoo"
46