Skip to content

Commit

Permalink
Wrap file paths in double quotes to prevent issues in file paths cont…
Browse files Browse the repository at this point in the history
…ain spaces
  • Loading branch information
Jordan Hall committed Aug 15, 2019
1 parent d7e23cb commit ed68bb4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/PdfStitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private function getShellCommand($filePath): string
throw new RuntimeException('Ghostscript (`gs`) is not installed. Please install it.');
}

$command = 'gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile='.$filePath.' ';
$command .= implode(' ', $this->inputFiles);
$command = 'gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile='.Utils::quote($filePath).' ';
$command .= implode(' ', array_map([Utils::class, 'quote'], $this->inputFiles));

return $command;
}
Expand Down
21 changes: 21 additions & 0 deletions src/Utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace LangleyFoxall\PdfStitcher;

/**
* Class Utils
* @package LangleyFoxall\PdfStitcher
*/
abstract class Utils
{
/**
* Wraps a specified string in double quotes and returns it.
*
* @param string $string
* @return string
*/
public static function quote(string $string)
{
return '"'.$string.'"';
}
}

0 comments on commit ed68bb4

Please sign in to comment.