Fix same-window folder drop guard
This commit is contained in:
@@ -164,7 +164,9 @@ function unav_guard_destination(string $source, string $destination): void {
|
||||
if (file_exists($destination)) {
|
||||
unav_error(409, 'Destination already exists');
|
||||
}
|
||||
if ($source === $destination || str_starts_with($destination, rtrim($source, '/') . '/')) {
|
||||
$normalizedSource = rtrim($source, '/');
|
||||
$normalizedDestination = rtrim($destination, '/');
|
||||
if ($normalizedSource === $normalizedDestination || (is_dir($source) && str_starts_with($normalizedDestination, $normalizedSource . '/'))) {
|
||||
unav_error(400, 'Destination cannot be inside source');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,9 @@ function unav_worker_guard(string $source, string $destination): void {
|
||||
if (file_exists($destinationPath)) {
|
||||
throw new RuntimeException('Destination already exists');
|
||||
}
|
||||
if ($sourceReal === $destinationPath || str_starts_with($destinationPath, rtrim($sourceReal, '/') . '/')) {
|
||||
$normalizedSource = rtrim($sourceReal, '/');
|
||||
$normalizedDestination = rtrim($destinationPath, '/');
|
||||
if ($normalizedSource === $normalizedDestination || (is_dir($sourceReal) && str_starts_with($normalizedDestination, $normalizedSource . '/'))) {
|
||||
throw new RuntimeException('Destination cannot be inside source');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user