Skip to content

Commit ec78507

Browse files
committed
dirname() should not normalize paths
This is the BC piece with the case where dirname() is used with an URL.
1 parent 403f352 commit ec78507

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

ext/standard/tests/dir/bug72625.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ while ($tmp > $base) {
4545
string(%d) "%s/_test/documents/projects/myproject/vendor/name/library/classpath"
4646
bool(true)
4747
string(%d) "%s\_test\documents\projects\myproject\vendor\name\library\classpath"
48-
string(%d) "%s\_test\documents\projects\myproject\vendor\name\library"
48+
string(%d) "%s/_test/documents/projects/myproject/vendor/name/library"
4949
string(%d) "%s/_test/documents/projects/myproject/vendor/name/library/classpath/../../../../../../../../_test/documents/projects/myproject/vendor/name/library/../../../../../../../_test/documents/projects/myproject/vendor/name/library/classpath"
5050
bool(true)
5151
string(%d) "%s\_test\documents\projects\myproject\vendor\name\library\classpath"
52-
string(%d) "%s\_test\documents\projects\myproject\vendor\name\library"
52+
string(%d) "%s/_test/documents/projects/myproject/vendor/name/library"
5353
===DONE===
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Test dirname() function : regression with path normalization
3+
--SKIPIF--
4+
<?php
5+
if(substr(PHP_OS, 0, 3) != "WIN")
6+
die("skip Only valid for Windows");
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$s = '/php_sanity/sanity.php?';
12+
while (dirname($s) == "/php_sanity" && strlen($s) < 10000) {
13+
$s .= str_repeat('X', 250);
14+
}
15+
16+
if (strlen($s) >= 10000) {
17+
echo "OK\n";
18+
} else {
19+
print "ERROR: " . PHP_EOL;
20+
var_dump(dirname($s));
21+
var_dump(strlen($s));
22+
}
23+
?>
24+
===DONE===
25+
--EXPECT--
26+
OK
27+
===DONE===

win32/ioutil.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,8 @@ PW32IO size_t php_win32_ioutil_dirname(char *path, size_t len)
445445

446446
start = path;
447447

448-
startw = pathw = php_win32_ioutil_conv_any_to_w(path, len, &pathw_len);
448+
/* Don't really care about the path normalization, pure parsing here. */
449+
startw = pathw = php_win32_cp_conv_any_to_w(path, len, &pathw_len);
449450
if (!pathw) {
450451
return 0;
451452
}

0 commit comments

Comments
 (0)