Skip to content

Commit

Permalink
Merge pull request #1988 from rakekniven/patch-5
Browse files Browse the repository at this point in the history
fix(i18n): Adapted Base64 occurences
  • Loading branch information
giovannism20 authored Dec 7, 2023
2 parents 67e19cc + 5318e80 commit 109c092
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/Helper/ValidateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function validateFile(array $data, int $type = self::TYPE_TO_SIGN): void
}
if (!empty($data['file']['url'])) {
if (!filter_var($data['file']['url'], FILTER_VALIDATE_URL)) {
throw new LibresignException($this->l10n->t('File type: %s. Specify a URL, a base64 string or a fileID.', [$this->getTypeOfFile($type)]));
throw new LibresignException($this->l10n->t('File type: %s. Specify a URL, a Base64 string or a fileID.', [$this->getTypeOfFile($type)]));
}
} elseif (!empty($data['file']['fileId'])) {
if (!is_numeric($data['file']['fileId'])) {
Expand All @@ -139,7 +139,7 @@ public function validateFile(array $data, int $type = self::TYPE_TO_SIGN): void
throw new LibresignException($this->l10n->t('Invalid data to validate file'), 404);
}
} else {
throw new LibresignException($this->l10n->t('File type: %s. Specify a URL, base64 string, path or a fileID.', [$this->getTypeOfFile($type)]));
throw new LibresignException($this->l10n->t('File type: %s. Specify a URL, Base64 string, path or a fileID.', [$this->getTypeOfFile($type)]));
}
}

Expand All @@ -159,17 +159,17 @@ public function validateBase64(string $base64, int $type = self::TYPE_TO_SIGN):
if (count($withMime) === 2) {
$withMime[0] = explode(';', $withMime[0]);
if (count($withMime[0]) !== 2) {
throw new LibresignException($this->l10n->t('File type: %s. Invalid base64 file.', [$this->getTypeOfFile($type)]));
throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)]));
}
if ($withMime[0][0] !== 'data:application/pdf' || $withMime[0][1] !== 'base64') {
throw new LibresignException($this->l10n->t('File type: %s. Invalid base64 file.', [$this->getTypeOfFile($type)]));
throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)]));
}
$base64 = $withMime[1];
}
$string = base64_decode($base64);
$newBase64 = base64_encode($string);
if ($newBase64 !== $base64) {
throw new LibresignException($this->l10n->t('File type: %s. Invalid base64 file.', [$this->getTypeOfFile($type)]));
throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)]));
}

$mimeType = $this->mimeTypeDetector->detectString($string);
Expand All @@ -178,7 +178,7 @@ public function validateBase64(string $base64, int $type = self::TYPE_TO_SIGN):
($type === self::TYPE_TO_SIGN && $mimeType !== 'application/pdf')
|| (in_array($type, [self::TYPE_VISIBLE_ELEMENT_USER, self::TYPE_VISIBLE_ELEMENT_PDF]) && $mimeType !== 'image/png')
) {
throw new LibresignException($this->l10n->t('File type: %s. Invalid base64 file.', [$this->getTypeOfFile($type)]));
throw new LibresignException($this->l10n->t('File type: %s. Invalid Base64 file.', [$this->getTypeOfFile($type)]));
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Helper/ValidateHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function testValidateFileWithEmptyFile() {
}

public function testValidateInvalidBase64File() {
$this->expectExceptionMessage('Invalid base64 file');
$this->expectExceptionMessage('Invalid Base64 file');

$user = $this->createMock(\OCP\IUser::class);
$this->getValidateHelper()->validateFile([
Expand All @@ -256,7 +256,7 @@ public function testValidateInvalidBase64File() {
*/
public function testValidateBase64($base64, $type, $valid) {
if (!$valid) {
$this->expectExceptionMessage('Invalid base64 file');
$this->expectExceptionMessage('Invalid Base64 file');
}
$return = $this->getValidateHelper()->validateBase64($base64, $type);
$this->assertNull($return);
Expand Down

0 comments on commit 109c092

Please sign in to comment.