Skip to content

Commit 81374fa

Browse files
committed
Fix encoding issue in TranscriptionMapService and improve error handling.
1 parent cb76ec2 commit 81374fa

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

app/Services/Helpers/TranscriptionMapService.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function __construct(protected array $reservedEncoded, protected array $m
3737
* Map transcription fields that are varied in database.
3838
*
3939
* @return mixed|string
40+
*
41+
* @throws \Throwable
4042
*/
4143
public function mapTranscriptionField(
4244
string $type,
@@ -45,7 +47,7 @@ public function mapTranscriptionField(
4547
): mixed {
4648
try {
4749
foreach ($this->mappedTranscriptionFields[$type] as $value) {
48-
$encodedValue = $this->decodeTranscriptionField($value);
50+
$encodedValue = $this->encodeTranscriptionField($value);
4951
if (isset($panoptesTranscription->{$encodedValue})) {
5052
return $panoptesTranscription->{$encodedValue};
5153
}
@@ -104,7 +106,14 @@ public function decodeTranscriptionField(string $field): false|string
104106
return $field;
105107
}
106108

107-
return $this->base64UrlDecode($field);
109+
$decoded = $this->base64UrlDecode($field);
110+
111+
// If decoding yields garbage or non-UTF8, it probably wasn't encoded
112+
if ($decoded === false || ! mb_check_encoding($decoded, 'UTF-8')) {
113+
return $field;
114+
}
115+
116+
return $decoded;
108117
}
109118

110119
/**

0 commit comments

Comments
 (0)