Substitute invalid UTF-8 in JSON error renderer output - #3465
Open
iliaal wants to merge 1 commit into
Open
Conversation
json_encode() returns false for strings with invalid UTF-8 sequences, so exception messages or titles carrying raw binary data produced an empty response body under a JSON content type. Pass JSON_INVALID_UTF8_SUBSTITUTE so invalid sequences are replaced with the UTF-8 replacement character instead of discarding the whole payload.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
json_encode()returnsfalsewhen any string in the payload contains an invalid UTF-8 sequence, so a JSON error response for an exception whose message or title carries raw binary data (invalid-UTF-8 user input echoed into exception messages is the common path) was emitted as a zero-length body underContent-Type: application/json. Strict API clients then fail to parse the empty body and the actual error information is silently discarded.This adds
JSON_INVALID_UTF8_SUBSTITUTEso invalid byte sequences are replaced with the UTF-8 replacement character instead of failing the whole encode. The renderer output stays valid JSON in all cases.Reproduction on 4.x before this change: