Skip to content

Commit 1a0706e

Browse files
[HttpFoundation] Fix parsing pathinfo with no leading slash
1 parent 3f38b8a commit 1a0706e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Request.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,9 +1983,8 @@ protected function preparePathInfo()
19831983
}
19841984

19851985
$pathInfo = substr($requestUri, \strlen($baseUrl));
1986-
if (false === $pathInfo || '' === $pathInfo) {
1987-
// If substr() returns false then PATH_INFO is set to an empty string
1988-
return '/';
1986+
if (false === $pathInfo || '' === $pathInfo || '/' !== $pathInfo[0]) {
1987+
return '/'.$pathInfo;
19891988
}
19901989

19911990
return $pathInfo;

Tests/RequestTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,16 @@ public static function getBaseUrlData()
18761876
'',
18771877
'/foo/api/bar',
18781878
],
1879+
[
1880+
'/api/index.phpfoo',
1881+
[
1882+
'SCRIPT_FILENAME' => '/var/www/api/index.php',
1883+
'SCRIPT_NAME' => '/api/index.php',
1884+
'PHP_SELF' => '/api/index.php',
1885+
],
1886+
'/api/index.php',
1887+
'/foo',
1888+
],
18791889
];
18801890
}
18811891

0 commit comments

Comments
 (0)