Skip to content

Commit

Permalink
fix join_paths issue with '0'
Browse files Browse the repository at this point in the history
  • Loading branch information
imanghafoori1 committed May 30, 2024
1 parent 92eda54 commit ed59e24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Filesystem/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
function join_paths($basePath, ...$paths)
{
foreach ($paths as $index => $path) {
if (empty($path)) {
if (empty($path) && $path != '0') {
unset($paths[$index]);
} else {
$paths[$index] = DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR);
Expand Down
20 changes: 18 additions & 2 deletions tests/Filesystem/JoinPathsHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ public static function unixDataProvider()
yield ['segments/get/ltrimed/by_directory/separator.php', join_paths('segments', '/get/ltrimed', '/by_directory/separator.php')];
yield ['only/\\os_separator\\/\\get_ltrimmed.php', join_paths('only', '\\os_separator\\', '\\get_ltrimmed.php')];
yield ['/base_path//does_not/get_trimmed.php', join_paths('/base_path/', '/does_not', '/get_trimmed.php')];
yield ['Empty/1/Segments/00/Get_removed.php', join_paths('Empty', '', '0', null, 0, false, [], '1', 'Segments', '00', 'Get_removed.php')];
yield ['Empty/0/1/Segments/00/Get_removed.php', join_paths('Empty', '', '0', null, 0, false, [], '1', 'Segments', '00', 'Get_removed.php')];
yield ['', join_paths(null, null, '')];
yield ['1/0/2/3', join_paths(1, 0, 2, 3)];
yield ['app/objecty', join_paths('app', new class()
{
public function __toString()
{
return 'objecty';
}
})];
yield ['app/0', join_paths('app', new class()
{
public function __toString()
{
return '0';
}
})];
}

#[RequiresOperatingSystem('Windows')]
Expand All @@ -47,14 +55,22 @@ public static function windowsDataProvider()
yield ['segments\get\ltrimed\by_directory\separator.php', join_paths('segments', '\get\ltrimed', '\by_directory\separator.php')];
yield ['only\\/os_separator/\\/get_ltrimmed.php', join_paths('only', '/os_separator/', '/get_ltrimmed.php')];
yield ['\base_path\\\\does_not\get_trimmed.php', join_paths('\\base_path\\', '\does_not', '\get_trimmed.php')];
yield ['Empty\1\Segments\00\Get_removed.php', join_paths('Empty', '', '0', null, 0, false, [], '1', 'Segments', '00', 'Get_removed.php')];
yield ['Empty\0\1\Segments\00\Get_removed.php', join_paths('Empty', '', '0', null, 0, false, [], '1', 'Segments', '00', 'Get_removed.php')];
yield ['', join_paths(null, null, '')];
yield ['1\0\2\3', join_paths(1, 0, 2, 3)];
yield ['app\\objecty', join_paths('app', new class()
{
public function __toString()
{
return 'objecty';
}
})];
yield ['app\\0', join_paths('app', new class()
{
public function __toString()
{
return '0';
}
})];
}
}

0 comments on commit ed59e24

Please sign in to comment.