1--TEST--
2Phar: create with illegal path
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
6--INI--
7phar.readonly=0
8phar.require_hash=1
9--FILE--
10<?php
11
12$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
13$pname = 'phar://' . $fname;
14
15@unlink($fname);
16
17file_put_contents($pname . '/a.php?', "query");
18file_put_contents($pname . '/b.php?bla', "query");
19
20var_dump(file_get_contents($pname . '/a.php'));
21var_dump(file_get_contents($pname . '/b.php'));
22
23function error_handler($errno, $errmsg)
24{
25	echo "Error: $errmsg\n";
26}
27
28set_error_handler('error_handler');
29
30$checks = array('/', '.', '../', 'a/..', 'a/', 'b//a.php');
31foreach($checks as $check)
32{
33	file_put_contents($pname . '/' . $check, "error");
34}
35
36$phar = new Phar($fname);
37$checks = array("a\0");
38foreach($checks as $check)
39{
40	try
41	{
42		$phar[$check] = 'error';
43	}
44	catch(Exception $e)
45	{
46		echo 'Exception: ' . $e->getMessage() . "\n";
47	}
48}
49
50?>
51===DONE===
52--CLEAN--
53<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
54--EXPECTF--
55string(5) "query"
56string(5) "query"
57Error: file_put_contents(phar://%s//): failed to open stream: phar error: file "" in phar "%s" cannot be empty
58Error: file_put_contents(phar://%s/.): failed to open stream: phar error: file "" in phar "%s" cannot be empty
59Error: file_put_contents(phar://%s/../): failed to open stream: phar error: file "" in phar "%s" cannot be empty
60Error: file_put_contents(phar://%s/a/..): failed to open stream: phar error: file "" in phar "%s" cannot be empty
61Exception: Entry a does not exist and cannot be created: phar error: invalid path "a" contains illegal character
62===DONE===
63