-
Notifications
You must be signed in to change notification settings - Fork 8k
Expand file tree
/
Copy pathbug54289.phpt
More file actions
76 lines (70 loc) · 2.45 KB
/
bug54289.phpt
File metadata and controls
76 lines (70 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
--TEST--
Bug #54289 Phar::extractTo() does not accept specific directories to be extracted
--EXTENSIONS--
phar
--INI--
phar.readonly = 0
--FILE--
<?php
// put our test fixtures into a far
$base = __DIR__.DIRECTORY_SEPARATOR.'bug54289'.DIRECTORY_SEPARATOR;
$inDir = $base.'in';
$phar = $base.'test.phar';
$pharA = new Phar($phar);
$pharA->buildFromDirectory($inDir);
// we should be able to pull out a directory that's there, but none that share
// the same prefix
$outDir = $base.'out';
$pharB = new Phar($phar);
$pharB->extractTo($outDir, 'dirA/', true);
var_dump(file_exists($outDir.DIRECTORY_SEPARATOR.'dirA'.DIRECTORY_SEPARATOR.'fileA'));
var_dump(file_exists($outDir.DIRECTORY_SEPARATOR.'dirA'.DIRECTORY_SEPARATOR.'fileB'));
var_dump(is_dir($outDir.DIRECTORY_SEPARATOR.'dirAB'));
// should also not be able to pull out non-existent ones
try {
$pharB->extractTo($outDir, 'dirX/', true);
echo 'failed to throw expected exception';
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage() . "\n";
}
// should also not be able to pull out /, because paths are not "rooted" that way
try {
$pharB->extractTo($outDir, '/', true);
echo 'failed to throw expected exception';
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage() . "\n";
}
// should be able to do by array, too
$pharB = new Phar($phar);
$pharB->extractTo($outDir, [ 'dirA/', 'dirAB/' ], true);
// but not an array with a bad member in it
try {
$pharB = new Phar($phar);
$pharB->extractTo($outDir, [ 'dirA/', 'dirX/' ], true);
echo 'failed to throw expected exception';
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage() . "\n";
}
echo 'done';
?>
--CLEAN--
<?php
$base = __DIR__.DIRECTORY_SEPARATOR.'bug54289'.DIRECTORY_SEPARATOR;
$phar = $base.'test.phar';
$outDir = $base.'out';
unlink($phar);
$iter = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(
$outDir, \FilesystemIterator::SKIP_DOTS|\FilesystemIterator::UNIX_PATHS),
\RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iter as $value) {
$value->isFile() ? unlink($value) : rmdir($value);
}
?>
--EXPECTF--
bool(true)
bool(true)
bool(false)
PharException: phar error: attempted to extract non-existent file or directory "dirX/" from phar "%sbug54289/test.phar"
PharException: phar error: attempted to extract non-existent file or directory "/" from phar "%sbug54289/test.phar"
PharException: phar error: attempted to extract non-existent file or directory "dirX/" from phar "%sbug54289/test.phar"
done