1--TEST--
2file() with various paths
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip non-windows only test');
7}
8?>
9--FILE--
10<?php
11
12$script_directory = __DIR__;
13chdir($script_directory);
14$test_dirname = basename(__FILE__, ".php") . "testdir";
15mkdir($test_dirname);
16
17$filepath = __FILE__ . ".tmp";
18$filename = basename($filepath);
19$fd = fopen($filepath, "w+");
20fwrite($fd, "Line 1\nLine 2\nLine 3");
21fclose($fd);
22
23echo "file() on a path containing .. and .\n";
24var_dump(file("./$test_dirname/../$filename"));
25
26echo "\nfile() on a path containing .. with invalid directories\n";
27var_dump(file("./$test_dirname/bad_dir/../../$filename"));
28
29echo "\nfile() on a linked file\n";
30$linkname = "somelink";
31var_dump(symlink($filepath, $linkname));
32var_dump(file($linkname));
33var_dump(unlink($linkname));
34
35echo "\nfile() on a relative path from a different working directory\n";
36chdir($test_dirname);
37var_dump(file("../$filename"));
38chdir($script_directory);
39
40chdir($script_directory);
41rmdir($test_dirname);
42unlink($filepath);
43
44?>
45--EXPECT--
46file() on a path containing .. and .
47array(3) {
48  [0]=>
49  string(7) "Line 1
50"
51  [1]=>
52  string(7) "Line 2
53"
54  [2]=>
55  string(6) "Line 3"
56}
57
58file() on a path containing .. with invalid directories
59array(3) {
60  [0]=>
61  string(7) "Line 1
62"
63  [1]=>
64  string(7) "Line 2
65"
66  [2]=>
67  string(6) "Line 3"
68}
69
70file() on a linked file
71bool(true)
72array(3) {
73  [0]=>
74  string(7) "Line 1
75"
76  [1]=>
77  string(7) "Line 2
78"
79  [2]=>
80  string(6) "Line 3"
81}
82bool(true)
83
84file() on a relative path from a different working directory
85array(3) {
86  [0]=>
87  string(7) "Line 1
88"
89  [1]=>
90  string(7) "Line 2
91"
92  [2]=>
93  string(6) "Line 3"
94}
95