1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-07-30 21:30:14 +02:00

fix: ignore partial json_encode() errors in JsonFormat (#2554)

Without this change, JsonFormat simply returns
an empty array. #2283
This commit is contained in:
dag
2022-03-29 22:45:00 +02:00
committed by GitHub
parent 060b4c7d58
commit 461269195b

View File

@@ -111,12 +111,15 @@ class JsonFormat extends FormatAbstract {
}
$data['items'] = $items;
$toReturn = json_encode($data, JSON_PRETTY_PRINT);
/**
* The intention here is to discard non-utf8 byte sequences.
* But the JSON_PARTIAL_OUTPUT_ON_ERROR also discards lots of other errors.
* So consider this a hack.
* Switch to JSON_INVALID_UTF8_IGNORE when PHP 7.2 is the latest platform requirement.
*/
$json = json_encode($data, JSON_PRETTY_PRINT | JSON_PARTIAL_OUTPUT_ON_ERROR);
// Remove invalid non-UTF8 characters
ini_set('mbstring.substitute_character', 'none');
$toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
return $toReturn;
return $json;
}
public function display(){