Bug Description
Json::encode() will not escape ampersands (& to \u0026) when the JSON_HEX_AMP flag is used. Instead, it will pretty print the output. The cause is that Json::PRETTY is defined as 0b0010, which equals 2, the same value as the PHP constant JSON_HEX_AMP.
Escaping ampersands is helpful for embedding json data into HTML.
Steps To Reproduce
Compare the output of json_encode against the output of Nette\Utils\Json::encode() when using the flag JSON_HEX_AMP.
echo json_encode($urls, JSON_HEX_AMP);
// VS
echo Nette\Utils\Json::encode($urls, JSON_HEX_AMP);
Expected Behavior
Given the following array:
$urls = ['http://foo.com?a=b&b=c', 'http://bar.com?a=b&b=c&d=a%20e'];
Calling Nette\Utils\Json::encode($urls, JSON_HEX_AMP); should output:
["http:\/\/foo.com?a=b\u0026b=c","http:\/\/bar.com?a=b\u0026b=c\u0026d=a%20e"]
Instead, it outputs:
[
"http://foo.com?a=b&b=c",
"http://bar.com?a=b&b=c&d=a%20e"
]
Possible Solution
Change the value of Nette\Utils\Json::PRETTY to something that is not already mapped to a built-in JSON flag.
Bug Description
Json::encode()will not escape ampersands (&to\u0026) when theJSON_HEX_AMPflag is used. Instead, it will pretty print the output. The cause is thatJson::PRETTYis defined as0b0010, which equals2, the same value as the PHP constantJSON_HEX_AMP.Escaping ampersands is helpful for embedding json data into HTML.
Steps To Reproduce
Compare the output of
json_encodeagainst the output ofNette\Utils\Json::encode()when using the flagJSON_HEX_AMP.Expected Behavior
Given the following array:
Calling
Nette\Utils\Json::encode($urls, JSON_HEX_AMP);should output:Instead, it outputs:
Possible Solution
Change the value of
Nette\Utils\Json::PRETTYto something that is not already mapped to a built-in JSON flag.