Problem/Motivation
The listener calls $final_response->setCharset($response->getCharset); With symfony 3, this works, because setCharset will take NULL and just use it, but in Symfony 4, $response->setCharset() requires a string, while ->getCharset() can return null. This creates the following error.
Exception: TypeError: Argument 1 passed to Symfony\Component\HttpFoundation\Response::setCharset() must be of the type string, null given, called in /var/www/html/core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php on line 176
Symfony\Component\HttpFoundation\Response->setCharset()() (Line: 496)Proposed resolution
We should only call setCharset if getCharset returns something other than NULL.
Remaining tasks
Do it
Commit it
User interface changes
None
API changes
None
Data model changes
None
Comments
Comment #2
mikelutzComment #3
mikelutzComment #4
mikelutzComment #5
mikelutzComment #6
mikelutzComment #7
jibranLet's not call the method again we can store the result in local var.
Comment #8
mikelutzThere ya go.
Comment #9
jibranThanks, for addressing the feedback.
These lines can be combined.
Comment #10
mikelutzMissed a semicolon anyway, lol. There you go.
Comment #11
mikelutzComment #12
jibranGreat!
Comment #13
wim leers👍 Looks good!
I don't think this needs backporting to the contrib module for use on Drupal 8.5/8.6, since sites on that core minor version will not be updating to Symfony 4.
Comment #14
alexpottCommitted 0df3be0 and pushed to 8.8.x. Thanks!
Will backport to 8.7.x once the branch is open again.
Comment #16
alexpottComment #19
wim leersPorted to the JSON:API contrib module: https://git.drupalcode.org/project/jsonapi/commit/d2bb36d