Problem/Motivation
When using cl_server to develop components, we try to use real content from our client's websites, which sometimes contains special characters like umlauts (ä, ö, ü). Those values get sent to the drupal backend and get rendered by cl_components. When doing so, the module puts the sent values through Json::encode in ComponentElement.php on line 115. Since drupal's Json::encode does not respect umlauts, they beak to Strings like "U00f6".
Steps to reproduce
Create a component with umlauts like "ö" in a demo content string when using cl_server and storybook for development.
Proposed resolution
Since the umlauts get sent to the drupal correctly but break on Json::encode while rendering and the core Json class does not provide a flag for this, replace
Json::encode($context)
with
json_encode($context, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE)
The flag "JSON_UNESCAPED_UNICODE" makes sure, that the encoding of the umlauts keeps working.
Remaining tasks
Review / Merge
User interface changes
None
API changes
None
Data model changes
None
Issue fork cl_components-3322979
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
fisherman90Issue fork now has my proposed resolution.
If anyone has a better way / ideas on this, it is very appreciated :)
At least for now this fixes my issues with the umlauts locally.
Comment #4
e0ipsoThis was fixed for SDC but not here: #3320239: String props are improperly encoded/decoded
Thanks for catching that!
Comment #6
e0ipsoFixed! Thanks for the contribution.
Comment #7
fisherman90Thanks for committing and for building this awesome module suite, looking forward on the developments coming up :)