Skip to content

Commit ddcd061

Browse files
committed
handle malformed json
1 parent 6b17dfc commit ddcd061

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/GettextPOGenerator.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ private function addStringsFromJsonFiles($translations) {
164164

165165
// Load each JSON file to get source strings
166166
foreach ($this->JsonFiles() as $jsonFile) {
167-
$jsonTranslations = json_decode(file_get_contents($jsonFile), true);
167+
$jsonTranslations = json_decode(file_get_contents($jsonFile), true);
168+
if (!is_array($jsonTranslations)) {
169+
throw new \Exception("The file '$jsonFile' is not valid JSON.'");
170+
}
168171

169172
foreach ($jsonTranslations as $key => $value) {
170173
$sourceStrings[] = $key;

0 commit comments

Comments
 (0)