Update JsonEncoder.php#4416
Conversation
Added JSON_INVALID_UTF8_IGNORE to $jsonEncodeOptions
dunglas
left a comment
There was a problem hiding this comment.
LGTM!
Could you rebase against the 2.6 branch as it's a bug fix and add a unit test to prevent any future regression please?
|
I had a few issues rebasing, so I guess it would be ok to start with 2.6? |
|
Just create a test that serializes a string containing invalid UTF-8 sequences. By the way, I wonder if it's a good idea to always enable this. Maybe should it be enabled only for the dev environment. Or maybe should would it be better to fix the exception message in Doctrine after all. I fear that generating JSON documents containing non-valid UTF-8 sequences in prod leads to more harm than good. |
|
Yeah, it was simple, I thought I had to do something with something from doctrine, but I got it. |
|
Not sure how to fix this is doctrine, as it's trying to insert binary data in a binary field in the DB |
|
Did this for testing: With the added flag (JSON_INVALID_UTF8_IGNORE) no exception was triggered. |
|
Regarding the test, you could use But I wonder if this is the best fix possible: api-platform/api-platform#2000 (comment) |
|
I've changed the test and branched from 2.6 but I can branch from main and then cherry pick. Is this still a valid approach? (the fix in the jsonencoder) |
|
sure, if you have issues just open a new pr no problem |
Added JSON_INVALID_UTF8_IGNORE to $jsonEncodeOptions