From 7aab6b9e769fab0b20619a844a07f5b186a0019e Mon Sep 17 00:00:00 2001 From: Iman Date: Thu, 30 May 2024 19:17:53 +0330 Subject: [PATCH] fix join_paths issue with '0' (#51649) --- src/Illuminate/Filesystem/functions.php | 2 +- tests/Filesystem/JoinPathsHelperTest.php | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Filesystem/functions.php b/src/Illuminate/Filesystem/functions.php index af39716f6e4f..761189a07cef 100644 --- a/src/Illuminate/Filesystem/functions.php +++ b/src/Illuminate/Filesystem/functions.php @@ -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); diff --git a/tests/Filesystem/JoinPathsHelperTest.php b/tests/Filesystem/JoinPathsHelperTest.php index 6b34efc21bd7..ddaba7a3a4a5 100644 --- a/tests/Filesystem/JoinPathsHelperTest.php +++ b/tests/Filesystem/JoinPathsHelperTest.php @@ -23,8 +23,9 @@ 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/2/3', join_paths(1, 0, 2, 3)]; yield ['app/objecty', join_paths('app', new class() { public function __toString() @@ -32,6 +33,13 @@ public function __toString() return 'objecty'; } })]; + yield ['app/0', join_paths('app', new class() + { + public function __toString() + { + return '0'; + } + })]; } #[RequiresOperatingSystem('Windows')] @@ -47,8 +55,9 @@ 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\2\3', join_paths(1, 2, 3)]; yield ['app\\objecty', join_paths('app', new class() { public function __toString() @@ -56,5 +65,12 @@ public function __toString() return 'objecty'; } })]; + yield ['app\\0', join_paths('app', new class() + { + public function __toString() + { + return '0'; + } + })]; } }