Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pretty unescaped json #1493

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

Daniel-KM
Copy link
Contributor

@Daniel-KM Daniel-KM commented Jan 6, 2020

The json standard doesn't require to escape anything, except ", \ and control characters. But php and Zend escape many other characters by default : tags, ampersand, apostrophe and overall the slashes "/" and the unicode characters, making json unreadable in many cases, whereas it's designed to be readable by people and machines.
So these commits fix this point in the most important cases. There are some other places to fix, but they are useful only for developers, so less important.
The last commit fixes the api output so it can be readable by people who don't have a json viewer in their browser (and of course it works fine in Next).

@Daniel-KM
Copy link
Contributor Author

Daniel-KM commented Jan 6, 2020

Maybe the flag JSON_UNESCAPED_LINE_TERMINATORS can be skipped.

@zerocrates
Copy link
Member

There are definitely some places where we want the default slash-escaping: in particular, in places where the JSON is being rendered inside HTML, or in particular inside a script tag, as that's what prevents JSON containing a closing script tag from ending the element.

@Daniel-KM
Copy link
Contributor Author

I checked the different places, and see that only one place has issue, in job params. This is fixed above. In fact, the json creation shall be separated from the escaping. For tags included in json, inside a script, it's allowed by the w3c validator.

@zerocrates
Copy link
Member

The issue with embedding in a script tag isn't about tags or angle brackets, etc. per se, its just about the output containing a closing script tag specifically.

<!DOCTYPE html>
<html>
<body>
<script>
<?php echo json_encode('</script><script>alert();</script>', JSON_UNESCAPED_SLASHES); ?>
</script>
</body>
</html>

The preceding code will run that alert, while the same call without JSON_UNESCAPED_SLASHES would not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants