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

Command icon 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

fisherman90 created an issue. See original summary.

fisherman90’s picture

Issue summary: View changes
Status: Active » Needs review

Issue 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.

e0ipso’s picture

This was fixed for SDC but not here: #3320239: String props are improperly encoded/decoded

Thanks for catching that!

  • e0ipso committed 383233f on 1.x authored by fisherman90
    Issue #3322979 by fisherman90, e0ipso: UTF-8 Umlauts in YML files break...
e0ipso’s picture

Status: Needs review » Fixed

Fixed! Thanks for the contribution.

fisherman90’s picture

Thanks for committing and for building this awesome module suite, looking forward on the developments coming up :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.