summaryrefslogtreecommitdiff
path: root/ext/phar/tests/phar_offset_get_error.phpt
blob: dade4726d9bfdd0b3e3c29c7259bc8df4da187a6 (plain)
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
--TEST--
Phar: ignore filenames starting with / on offsetSet
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
--INI--
phar.readonly=0
phar.require_hash=1
--FILE--
<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
$pname = 'phar://'.$fname;
$iname = '/file.txt';
$ename = '/error/..';

$p = new Phar($fname);
$p[$iname] = "foobar\n";

try
{
	$p[$ename] = "foobar\n";
}
catch(Exception $e)
{
	echo $e->getMessage() . "\n";
}

include($pname . $iname);

// extra coverage
try {
$p['.phar/oops'] = 'hi';
} catch (Exception $e) {
echo $e->getMessage(),"\n";
}
try {
$a = $p['.phar/stub.php'];
} catch (Exception $e) {
echo $e->getMessage(),"\n";
}
?>
===DONE===
--CLEAN--
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
--EXPECT--
Entry /error/.. does not exist and cannot be created: phar error: invalid path "/error/.." contains upper directory reference
foobar
Cannot set any files or directories in magic ".phar" directory
Entry .phar/stub.php does not exist
===DONE===