mirror of
https://github.com/archtechx/tenancy.git
synced 2026-09-20 11:14:03 +00:00
Handle non-UTF-8 paths in normalizePath()
Because str($foo)->deduplicate(...) returns null when $foo contains non-UTF-8 chars, normalizePath() would return just "". Now, the method returns the not-deduplicated, normalized path instead.
This commit is contained in:
parent
189c2b7436
commit
ca9afad3a5
1 changed files with 11 additions and 5 deletions
|
|
@ -254,7 +254,13 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
|||
return $configuredPath . DIRECTORY_SEPARATOR . $suffix;
|
||||
}
|
||||
|
||||
/** Normalize the path to use the separator of the current OS, deduplicated. */
|
||||
/**
|
||||
* Normalize the path to use the separator of the current OS.
|
||||
*
|
||||
* The separators are also deduplicated, with two exceptions:
|
||||
* - if the path begins with \\ on Windows (i.e. a UNC path), the *leading* separators won't end up deduplicated
|
||||
* - if the path contains non-UTF-8 characters, the separators won't be deduplicated at all (since str()->deduplicate() only works on UTF-8 strings).
|
||||
*/
|
||||
protected function normalizePath(string $path): string
|
||||
{
|
||||
$path = str_replace('/', DIRECTORY_SEPARATOR, $path);
|
||||
|
|
@ -263,10 +269,10 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
|||
// so the leading separator that got collapsed by deduplicate() should be added back.
|
||||
$uncPrefix = DIRECTORY_SEPARATOR === '\\' && str_starts_with($path, '\\\\') ? DIRECTORY_SEPARATOR : '';
|
||||
|
||||
return $uncPrefix . str($path)
|
||||
->deduplicate(DIRECTORY_SEPARATOR)
|
||||
->rtrim(DIRECTORY_SEPARATOR)
|
||||
->toString();
|
||||
// Since deduplicate() only supports UTF-8 paths, paths with non-UTF-8 characters will keep the duplicate separators.
|
||||
$path = str($path)->deduplicate(DIRECTORY_SEPARATOR)->toString() ?: $path;
|
||||
|
||||
return $uncPrefix . rtrim($path, DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
public function scopeSessions(string|false $suffix): void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue