Skip to content

Commit

Permalink
Merge pull request #10 from maximehuran/feature/correct-clean-path
Browse files Browse the repository at this point in the history
Avoid error on files with `.` in name
  • Loading branch information
maximehuran authored Aug 25, 2023
2 parents 686c1a3 + e2461ef commit 1f82bd8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Helper/FileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ public function list(string $path, ?string $folder = null): array

$cleanPath = $this->cleanPath($path);
$filePath = (!empty($cleanPath) ? $cleanPath . '/' : '') . $fileName;
$files[] = new File($fileName, $filePath, $this->getFullPath($filePath));

// If the cleaned path generate a weird path, check the file still exists
$fullFilePath = $this->getFullPath($filePath);
if (!file_exists($fullFilePath)) {
continue;
}

$files[] = new File($fileName, $filePath, $fullFilePath);
}

return $files;
Expand Down Expand Up @@ -290,6 +297,10 @@ public function deleteFile(string $path, ?string $folder = null): string
*/
public function cleanPath(string $path): string
{
if (false === strpos($path, '/')) {
return $path;
}

$path = trim($path, '.');
$path = str_replace('/..', '', (string) $path);
$path = str_replace('/.', '', (string) $path);
Expand Down

0 comments on commit 1f82bd8

Please sign in to comment.