xref: /PHP-7.1/ext/phar/tests/bug64931/bug64931.phpt (revision 7af945e2)
1--TEST--
2Bug #64931 (phar_add_file is too restrictive on filename)
3--SKIPIF--
4<?php extension_loaded("phar") or die("skip need ext/phar support"); ?>
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9
10echo "Test\n";
11
12@unlink(__DIR__."/bug64931.phar");
13$phar = new Phar(__DIR__."/bug64931.phar");
14$phar->addFile(__DIR__."/src/.pharignore", ".pharignore");
15try {
16	$phar->addFile(__DIR__."/src/.pharignore", ".phar/gotcha");
17} catch (Exception $e) {
18	echo "CAUGHT: ". $e->getMessage() ."\n";
19}
20
21try {
22	$phar->addFromString(".phar", "gotcha");
23} catch (Exception $e) {
24	echo "CAUGHT: ". $e->getMessage() ."\n";
25}
26
27try {
28	$phar->addFromString(".phar//", "gotcha");
29} catch (Exception $e) {
30	echo "CAUGHT: ". $e->getMessage() ."\n";
31}
32
33try {
34	$phar->addFromString(".phar\\", "gotcha");
35} catch (Exception $e) {
36	echo "CAUGHT: ". $e->getMessage() ."\n";
37}
38
39try {
40	$phar->addFromString(".phar\0", "gotcha");
41} catch (Exception $e) {
42	echo "CAUGHT: ". $e->getMessage() ."\n";
43}
44
45?>
46===DONE===
47--CLEAN--
48<?php
49@unlink(__DIR__."/bug64931.phar");
50?>
51--EXPECTF--
52Test
53CAUGHT: Cannot create any files in magic ".phar" directory
54CAUGHT: Cannot create any files in magic ".phar" directory
55CAUGHT: Cannot create any files in magic ".phar" directory
56CAUGHT: Cannot create any files in magic ".phar" directory
57
58Warning: Phar::addFromString() expects parameter 1 to be a valid path, string given in %s%ebug64931.php on line %d
59===DONE===
60