Skip to content

Commit b286cca

Browse files
committed
Merge branch 'master' of github.com:heiglandreas/Org_Heigl_Ghostscript
2 parents de61fee + ec0a899 commit b286cca

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

.travis.yml

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sudo: false
2+
dist: trusty
23

34
language: php
45

@@ -21,6 +22,11 @@ env:
2122
- GH_REF: github.com:heiglandreas/Org_Heigl_Ghostscript.git
2223
- ENCRYPTION_LABEL: "f38516f65eab"
2324

25+
addons:
26+
apt:
27+
packages:
28+
- ghostscript
29+
2430
matrix:
2531
fast_finish: true
2632
include:
@@ -55,6 +61,9 @@ matrix:
5561
- php: 7.1
5662
env:
5763
- DEPS=latest
64+
- php: 7.2
65+
env:
66+
- DEPS=latest
5867
- php: nightly
5968
env:
6069
- DEPS=lowest

src/Ghostscript.php

+23-9
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public static function setGsPath($path = null)
282282
throw new \InvalidArgumentException('The given file is not executable');
283283
}
284284

285-
@exec($path . ' -v', $result);
285+
@exec('"' . $path . '" -v', $result);
286286
$content = implode("\n", $result);
287287
if (false === stripos($content, 'ghostscript')) {
288288
throw new \InvalidArgumentException('No valid Ghostscript found');
@@ -363,9 +363,10 @@ public function getInputFile()
363363
*/
364364
public function setOutputFile($name = 'output')
365365
{
366-
if (0 !== strpos($name, DIRECTORY_SEPARATOR)) {
366+
if ($this->isRelative($name)) {
367367
$name = $this->getBasePath() . DIRECTORY_SEPARATOR . $name;
368368
}
369+
369370
$this->outfile = $name;
370371

371372
return $this;
@@ -382,7 +383,7 @@ public function setOutputFile($name = 'output')
382383
*/
383384
public function getOutputFile()
384385
{
385-
if (0 !== strpos($this->outfile, DIRECTORY_SEPARATOR)) {
386+
if ($this->isRelative($this->outfile)) {
386387
return $this->getBasePath() . DIRECTORY_SEPARATOR . $this->outfile;
387388
}
388389

@@ -440,7 +441,7 @@ public function getRenderString()
440441
if (null === $this->getInputFile()) {
441442
return '';
442443
}
443-
$string = self::getGsPath();
444+
$string = '"' . self::getGsPath() . '"';
444445
$string .= ' -dSAFER -dQUIET -dNOPLATFONTS -dNOPAUSE -dBATCH';
445446
$string .= ' -sOutputFile="' . $this->getOutputFileName() . '"';
446447
$string .= $this->getDevice()->getParameterString();
@@ -652,11 +653,11 @@ public function setUseCie($useCie = true)
652653
return $this;
653654
}
654655

655-
/**
656-
* Shall we use the CIE map for color-conversions?
657-
*
658-
* @return boolean
659-
*/
656+
/**
657+
* Shall we use the CIE map for color-conversions?
658+
*
659+
* @return boolean
660+
*/
660661
public function useCie()
661662
{
662663
return (bool) $this->useCie;
@@ -889,6 +890,19 @@ public function getOutputFileName()
889890

890891
return $basename;
891892
}
893+
894+
private function isRelative($path)
895+
{
896+
if (0 === strpos($path, DIRECTORY_SEPARATOR)) {
897+
return false;
898+
}
899+
900+
if (1 === strpos($path, ':\\') && preg_match('/^[A-Za-z]/', $path)) {
901+
return false;
902+
}
903+
904+
return true;
905+
}
892906
}
893907

894908
try {

tests/GhostscriptTest.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function testRenderingStrings()
185185
$f = new Ghostscript();
186186
$dir = __DIR__ . DIRECTORY_SEPARATOR . 'support' . DIRECTORY_SEPARATOR;
187187
$filename = $dir . 'test.pdf';
188-
$path = Ghostscript::getGsPath();
188+
$path = '"' . Ghostscript::getGsPath() . '"';
189189
$this->assertEquals('', $f->getRenderString());
190190
$f->setInputFile($filename);
191191
$expect = $path . ' -dSAFER -dQUIET -dNOPLATFONTS -dNOPAUSE -dBATCH -sOutputFile="' . $dir . 'output.png" -sDEVICE=pngalpha -r72 "' .$filename . '"';
@@ -288,4 +288,25 @@ public function testThatSettingPathToSomethingGsLikeWorks()
288288
Ghostscript::class
289289
);
290290
}
291+
292+
/** @dataProvider provideRelativePaths */
293+
public function testThatRelativePathsAreCorrectlyDetected($path, $result)
294+
{
295+
$reflection = new \ReflectionClass(Ghostscript::class);
296+
$method = $reflection->getMethod('isRelative');
297+
$method->setAccessible(true);
298+
299+
$this->assertSame($result, $method->invokeArgs(new Ghostscript(), [$path]));
300+
}
301+
302+
public function provideRelativePaths()
303+
{
304+
return [
305+
['/test/foo', false],
306+
['a:\foo', false],
307+
['bar', true],
308+
['\foob', true],
309+
['a:/test', true],
310+
];
311+
}
291312
}

0 commit comments

Comments
 (0)