Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,11 @@ public function getCommand(): string
/**
* Escapes a string in order to inject it in the shell command.
*/
public function escape(string $string, bool $addQuotes = true): string
public function escape(string $string): string
{
$string = str_replace(
['"', '`', '’', '\\\''],
['\"', "'", "'", "'"],
trim($string)
);
$string = escapeshellarg($string);

return $addQuotes ? '"'.$string.'"' : $string;
return $string;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions Tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function testCommandString($source, $output, $geometry, $quality)

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

Expand Down Expand Up @@ -197,13 +197,13 @@ public function testInexistingFiles()

public function testEscape()
{
$string = 'PSR\'s a great `code` style standard. ';
$string = '25% $(touch hacked) #';

$command = new Command(IMAGEMAGICK_DIR);

$escaped = $command->escape($string, true);
$escaped = $command->escape($string);

$this->assertEquals('"PSR\'s a great \'code\' style standard."', $escaped);
$this->assertEquals("'25% $(touch hacked) #'", $escaped);
}

}