Skip to content

Commit

Permalink
Merge pull request #4624 from LibreSign/fix/use-entities-instead-of-c…
Browse files Browse the repository at this point in the history
…har-converting

fix: use entities instead of char convertoing
  • Loading branch information
samuelsonbrito authored Feb 12, 2025
2 parents 8c1a06c + 1f7870f commit 86c08b3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lib/Handler/FooterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ public function setTemplateVar(string $name, mixed $value): self {
}

private function getTemplateVars(): array {
$this->templateVars['signedBy'] = iconv(
'UTF-8',
'windows-1252',
$this->appConfig->getValueString(Application::APP_ID, 'footer_signed_by', $this->l10n->t('Digital signed by LibreSign.'))
);
$this->templateVars['signedBy'] = $this->appConfig->getValueString(Application::APP_ID, 'footer_signed_by', $this->l10n->t('Digital signed by LibreSign.'));

$this->templateVars['linkToSite'] = $this->appConfig->getValueString(Application::APP_ID, 'footer_link_to_site', 'https://libresign.coop');

Expand All @@ -130,6 +126,10 @@ private function getTemplateVars(): array {
$this->templateVars['validateIn'] = $this->l10n->t('Validate in %s.', ['%s']);
}

foreach ($this->templateVars as $key => $value) {
$this->templateVars[$key] = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8');
}

if ($this->appConfig->getValueBool(Application::APP_ID, 'write_qrcode_on_footer', true)) {
$this->templateVars['qrcode'] = $this->getQrCodeImageBase64($this->templateVars['validationSite']);
}
Expand Down
47 changes: 41 additions & 6 deletions tests/Unit/Handler/FooterHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public function testGetFooterWithSuccess(array $settings, array $expected): void
};
});
$pdf = $this->getClass()
->setTemplateVar('test', 'fake value')
->getFooter($file, $libresignFile);
if ($settings['add_footer']) {
$actual = $this->extractPdfContent($pdf, array_keys($expected));
Expand Down Expand Up @@ -118,7 +117,6 @@ public static function dataGetFooterWithSuccess(): array {
qrcodeSize:<?= $qrcodeSize ?><br />
signedBy:<?= $signedBy ?><br />
validateIn:<?= $validateIn ?><br />
test:<?= $test ?><br />
qrcode:<?= $qrcode ?>
</div>
HTML,
Expand All @@ -128,7 +126,6 @@ public static function dataGetFooterWithSuccess(): array {
'qrcodeSize' => '108',
'signedBy' => 'Digital signed by LibreSign.',
'validateIn' => 'Validate in %s.',
'test' => 'fake value',
]
],
[
Expand All @@ -143,16 +140,54 @@ public static function dataGetFooterWithSuccess(): array {
<div style="font-size:8px;">
signedBy:<?= $signedBy ?><br />
validateIn:<?= $validateIn ?><br />
test:<?= $test ?>
</div>
HTML,
],
[
'signedBy' => 'Digital signed by LibreSign.',
'validateIn' => 'Validate in %s.',
'test' => 'fake value',
]
]
],
[
[
'add_footer' => true,
'validation_site' => 'http://test.coop',
'write_qrcode_on_footer' => false,
'footer_link_to_site' => 'https://libresign.coop',
'footer_signed_by' => 'Signé numériquement avec LibreSign.',
'footer_validate_in' => 'Validate in %s',
'footer_template' => <<<'HTML'
<div style="font-size:8px;">
signedBy:<?= $signedBy ?><br />
validateIn:<?= $validateIn ?><br />
</div>
HTML,
],
[
'signedBy' => 'Signé numériquement avec LibreSign.',
'validateIn' => 'Validate in %s',
]
],
[
[
'add_footer' => true,
'validation_site' => 'http://test.coop',
'write_qrcode_on_footer' => false,
'footer_link_to_site' => 'https://libresign.coop',
'footer_signed_by' => 'Το αρχείο υπάρχει',
'footer_validate_in' => 'Validate in %s.',
'footer_template' => <<<'HTML'
<div style="font-size:8px;">
signedBy:<?= $signedBy ?><br />
validateIn:<?= $validateIn ?><br />
</div>
HTML,
],
[
'signedBy' => 'Το αρχείο υπάρχει',
'validateIn' => 'Validate in %s.',
]
],
];
}

Expand Down

0 comments on commit 86c08b3

Please sign in to comment.