Skip to content

Commit

Permalink
Fix inconsistencies in path cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierstoval committed Dec 9, 2024
1 parent ef89b11 commit 08ad138
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,11 @@ public function testCommandString($source, $output, $geometry, $quality, $format
;

$expected = \implode(' ', $command->getExecutable('convert')).
' '.$source.
' \''.$source.'\''.
' -thumbnail "'.$geometry.'"'.
' -quality '.$quality.
' -page "'.$format.'"'.
' '.$output;
' \''.$output.'\'';

$expected = \str_replace('\\', '/', $expected);

Expand Down
8 changes: 5 additions & 3 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function create(?string $magickBinaryPath = null): self
public static function findMagickBinaryPath(?string $magickBinaryPath): string
{
// Delete trimming directory separator
$magickBinaryPath = self::cleanPath((string) $magickBinaryPath, true);
$magickBinaryPath = self::cleanPath((string) $magickBinaryPath, true, false);

if (!$magickBinaryPath) {
$magickBinaryPath = (new ExecutableFinder())->find('magick');
Expand All @@ -118,15 +118,17 @@ public static function findMagickBinaryPath(?string $magickBinaryPath): string
return $magickBinaryPath;
}

private static function cleanPath(string $path, bool $rtrim = false): string
private static function cleanPath(string $path, bool $rtrim = false, bool $escape = true): string
{
$path = \str_replace('\\', '/', $path);

if ($rtrim) {
$path = \rtrim($path, '/');
}

$path = \escapeshellarg($path);
if ($escape) {
$path = \escapeshellarg($path);
}

return $path;
}
Expand Down

0 comments on commit 08ad138

Please sign in to comment.