Skip to content

Commit fe485e3

Browse files
committed
fix: should add / at start for realpath()
Signed-off-by: inhere <[email protected]>
1 parent d20bff9 commit fe485e3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Traits/FileSystemFuncTrait.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use function array_values;
2121
use function copy;
2222
use function error_get_last;
23+
use function explode;
2324
use function function_exists;
2425
use function implode;
2526
use function is_dir;
@@ -171,9 +172,15 @@ public static function realpath(string $path): string
171172
return '';
172173
}
173174

174-
// ~: is user home dir in *nix OS
175-
if ($parts[0] === '~' && false === OS::isWindows()) {
176-
$parts[0] = OS::getUserHomeDir();
175+
$start = '';
176+
$isUnix = DIRECTORY_SEPARATOR === '/';
177+
if ($isUnix) {
178+
// ~: is user home dir in *nix OS
179+
if ($parts[0] === '~') {
180+
$parts[0] = OS::getUserHomeDir();
181+
} else {
182+
$start = '/';
183+
}
177184
}
178185

179186
$absolutes = [];
@@ -189,7 +196,7 @@ public static function realpath(string $path): string
189196
}
190197
}
191198

192-
return implode(DIRECTORY_SEPARATOR, $absolutes);
199+
return $start . implode(DIRECTORY_SEPARATOR, $absolutes);
193200
}
194201

195202
/**********************************************************************************

0 commit comments

Comments
 (0)