Skip to content

Commit 78223be

Browse files
committed
Fix import files with UTF-8 BOM
1 parent 7404a0d commit 78223be

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

source/Controllers/CollectionController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public function importFile($documentsFilename, $databaseName, $collectionName) :
8989
throw new \Exception('Impossible to read the import file.');
9090
}
9191

92+
// Remove UTF-8 BOM from uploaded file since UTF-8 BOM can disturb decoding of JSON.
93+
$documentsFileContents = preg_replace('/\x{FEFF}/u', '', $documentsFileContents, 1);
94+
9295
$documents = json_decode($documentsFileContents, JSON_OBJECT_AS_ARRAY);
9396

9497
if ( is_null($documents) ) {

0 commit comments

Comments
 (0)