Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
fix: ignore partial json_encode() errors in JsonFormat (RSS-Bridge#2554)
Browse files Browse the repository at this point in the history
Without this change, JsonFormat simply returns
an empty array. RSS-Bridge#2283
  • Loading branch information
dvikan authored and Kwbmm committed Jun 17, 2022
1 parent c837489 commit 4304780
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions formats/JsonFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ public function stringify(){
}
$data['items'] = $items;

$toReturn = json_encode($data, JSON_PRETTY_PRINT);

// Remove invalid non-UTF8 characters
ini_set('mbstring.substitute_character', 'none');
$toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
return $toReturn;
/**
* 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);

return $json;
}

public function display(){
Expand Down

0 comments on commit 4304780

Please sign in to comment.