Skip to content

Commit c80de15

Browse files
authored
Merge pull request #20 from JSignPdf/fix/escape-password
Fix/escape password
2 parents 9c6945d + 070109d commit c80de15

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/Sign/JSignService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ private function commandSign(JSignParam $params)
111111
}
112112
$this->throwIf(!file_exists($jSignPdf), 'Jar of JSignPDF not found on path: '. $jSignPdf);
113113

114-
return "$java -jar $jSignPdf $pdf -ksf $certificate -ksp '{$params->getPassword()}' {$params->getJSignParameters()} -d {$params->getPathPdfSigned()} 2>&1";
114+
$password = escapeshellarg($params->getPassword());
115+
return "$java -jar $jSignPdf $pdf -ksf $certificate -ksp {$password} {$params->getJSignParameters()} -d {$params->getPathPdfSigned()} 2>&1";
115116
}
116117

117118
private function javaCommand(JSignParam $params)

tests/JSignPDFTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ public function testSignSuccess()
6767
$this->assertNotNull($fileSigned);
6868
}
6969

70+
public function testSignUsingPasswordWithQuote()
71+
{
72+
if (!class_exists('JSignPDF\JSignPDFBin\JavaCommandService')) {
73+
$this->markTestSkipped('Install jsignpdf/jsignpdf-bin');
74+
}
75+
$params = JSignParamBuilder::instance()->withDefault();
76+
$password = "with ' quote";
77+
$params->setCertificate($this->getNewCert($password));
78+
$params->setPassword($password);
79+
$fileSigned = $this->service->sign($params);
80+
$this->assertNotNull($fileSigned);
81+
}
82+
7083
public function testCertificateExpired()
7184
{
7285
if (!class_exists('JSignPDF\JSignPDFBin\JavaCommandService')) {

0 commit comments

Comments
 (0)