Skip to content

Commit e30c606

Browse files
Scrub invalid UTF-8 characters in decompress testoutput migration (#2971)
We encountered the following error while attempting to run this migration for slicer.cdash.org ``` SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0xe2 0x43 0x6f ```
1 parent 0cb707e commit e30c606

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

database/migrations/2025_06_16_152800_decompress_test_output.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ public function up(): void
3838
if ($output === false) {
3939
throw new Exception('Error reading stream from database.');
4040
}
41-
$values[] = $this->decompressOutput($output);
41+
$decompressed = $this->decompressOutput($output);
42+
if (mb_detect_encoding($decompressed, 'UTF-8', true) === false) {
43+
$decompressed = mb_convert_encoding($decompressed, 'UTF-8', 'UTF-8');
44+
if ($decompressed === false) {
45+
echo "Unable to convert testoutput #{$row->id} to UTF-8\n";
46+
$decompressed = '';
47+
}
48+
}
49+
$values[] = $decompressed;
4250
}
4351

4452
// Remove the trailing comma...

0 commit comments

Comments
 (0)