Skip to content

Commit d1cb1a4

Browse files
author
Matthias Isler
committed
fixed bug with options without values
1 parent 97555ef commit d1cb1a4

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
### Fixed
99

10+
## [2.0.2] - 2016-09-20
11+
### Fixed
12+
- Fixed a bug with options without values
13+
1014
## [2.0.1] - 2016-05-19
1115
### Fixed
1216
- Fixed a critical bug

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ $input->setUrl('https://www.google.com');
5050

5151
$converter = new Converter($input, new DownloadOutput());
5252

53+
$converter->setOption('n');
5354
$converter->setOption('d', '300');
55+
5456
$converter->setOptions([
57+
'no-background',
5558
'margin-bottom' => '100',
5659
'margin-top' => '100',
5760
]);

src/Spiritix/HtmlToPdf/Converter.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ public function setOptions($options)
152152
}
153153

154154
foreach ($options as $key => $value) {
155+
156+
// Convert key-only options to regular ones
157+
if (is_numeric($key) && !empty($value)) {
158+
$key = $value;
159+
$value = '';
160+
}
161+
155162
$this->setOption($key, $value);
156163
}
157164

@@ -225,9 +232,9 @@ private function buildCommand()
225232
}
226233

227234
$key = escapeshellcmd(trim($key));
228-
$value = escapeshellarg(trim($value));
235+
$value = trim($value);
229236

230-
$optionsString .= $key . ' ' . $value . ' ';
237+
$optionsString .= $key . (empty($value) ? '' : ' ' . escapeshellarg($value)) . ' ';
231238
}
232239

233240
$command = $this->getBinaryPath() . ' ' . $optionsString . ' - -';

tests/ConverterTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ public function setUp()
2525

2626
public function testOptions()
2727
{
28+
$this->converter->setOption('n');
2829
$this->converter->setOption('R', '500');
2930
$this->converter->setOption('margin-top', '100');
3031

3132
$this->converter->setOptions([
33+
'ignore-load-errors',
3234
'B' => '50',
3335
'margin-left' => '10',
3436
]);
3537

38+
$value = $this->converter->getOption('n');
39+
$this->assertEquals('', $value);
40+
3641
$value = $this->converter->getOption('R');
3742
$this->assertEquals('500', $value);
3843

@@ -41,8 +46,10 @@ public function testOptions()
4146

4247
$options = $this->converter->getOptions();
4348
$this->assertEquals([
49+
'n' => '',
4450
'R' => '500',
4551
'margin-top' => '100',
52+
'ignore-load-errors' => '',
4653
'B' => '50',
4754
'margin-left' => '10',
4855
], $options);

0 commit comments

Comments
 (0)