Skip to content

Commit

Permalink
Made the JSON output code more resilient
Browse files Browse the repository at this point in the history
  • Loading branch information
pmeenan committed Mar 29, 2016
1 parent 2a3e6fb commit d806312
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions www/common_lib.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1933,14 +1933,23 @@ function json_response(&$response) {
if( array_key_exists('r', $_REQUEST) && strlen($_REQUEST['r']) )
$ret['requestId'] = $_REQUEST['r'];

$out = null;
if (version_compare(phpversion(), '5.4.0') >= 0 &&
array_key_exists('pretty', $_REQUEST) &&
$_REQUEST['pretty']) {
echo json_encode($response, JSON_PRETTY_PRINT);
$out = json_encode($response, JSON_PRETTY_PRINT);
} else {
echo json_encode($response);
$out = json_encode($response);
}

if (!isset($out) || $out === false || !is_string($out) || strlen($out) < 3) {
require_once('lib/json.php');
$jsonLib = new Services_JSON();
$out = $jsonLib->encode($response);
}

echo $out;

if( isset($_REQUEST['callback']) && strlen($_REQUEST['callback']) )
echo ");";
}
Expand Down

0 comments on commit d806312

Please sign in to comment.