Skip to content

Commit 0275e69

Browse files
committed
Fix logic bug
1 parent 7f97c94 commit 0275e69

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

system/HTTP/URI.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static function createURIString(string $scheme = null, string $authority
193193
*
194194
* @param string $path
195195
*
196-
* @return string
196+
* @return string
197197
* @internal
198198
*/
199199
public static function removeDotSegments(string $path): string
@@ -230,21 +230,18 @@ public static function removeDotSegments(string $path): string
230230
}
231231

232232
$output = implode('/', $output);
233-
$output = ltrim($output, '/ ');
233+
$output = trim($output, '/ ');
234234

235-
if ($output !== '/')
235+
// Add leading slash if necessary
236+
if (strpos($path, '/') === 0)
236237
{
237-
// Add leading slash if necessary
238-
if (strpos($path, '/') === 0)
239-
{
240-
$output = '/' . $output;
241-
}
238+
$output = '/' . $output;
239+
}
242240

243-
// Add trailing slash if necessary
244-
if (substr($path, -1, 1) === '/')
245-
{
246-
$output .= '/';
247-
}
241+
// Add trailing slash if necessary
242+
if ($output !== '/' && substr($path, -1, 1) === '/')
243+
{
244+
$output .= '/';
248245
}
249246

250247
return $output;

tests/system/HTTP/URITest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,10 @@ public function defaultDots()
591591
'/..',
592592
'/',
593593
],
594+
[
595+
'//',
596+
'/',
597+
],
594598
[
595599
'/foo/..',
596600
'/',

0 commit comments

Comments
 (0)