-
-
Notifications
You must be signed in to change notification settings - Fork 152
Closed
Description
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.
Metadata
Metadata
Assignees
Labels
No labels