Problem/Motivation

We have a story with this parameter:

{"text":"Cat\u00e9gorie #2","url":"http:\/\/google.com"}

ServerController renders it like this:

<a href="http://google.com">Cat&Atilde;&copy;gorie #2</a>

Steps to reproduce

Here is our story:

{"title":"Components\/molecules\/navigation\/breadcrumb","parameters":{"server":{"url":"http:\/\/drupal.docksal.site\/storybook\/stories\/render"}},"stories":[{"args":{"breadcrumb":[{"text":"Homepage","url":"http:\/\/google.com"},{"text":"Cat\u00e9gorie #2","url":"http:\/\/google.com"},{"text":"Sous-cat\u00e9gorie avec un lien bcp plus long #3"}]},"parameters":{"server":{"id":"eyJwYXRoIjoidGhlbWVzXC9jdXN0b21cL2Zyb250XC9jb21wb25lbnRzXC9tb2xlY3VsZXNcL25hdmlnYXRpb25cL2JyZWFkY3J1bWJcL2JyZWFkY3J1bWIuc3Rvcmllcy50d2lnIiwiaWQiOiJkZWZhdWx0In0%3D"}},"name":"default"}]}

Proposed resolution

I think $dom->loadHTML() does not detect the encoding correctly.
Using Html::load() is a better practice and seems to fix the issue.

Issue fork storybook-3444146

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

prudloff created an issue. See original summary.

prudloff’s picture

Status: Active » Needs review
StatusFileSize
new878 bytes

GitLab fails to create the issue fork for some reason so here is a patch.

prudloff’s picture

StatusFileSize
new1002 bytes

Turns out Html::load() removes everything outside the body so this is not what we need here.
The root problem seems to be that DOMDocument::loadHTML() does not detect the encoding correctly. Forcing it like this works but does not feel very clean:

    $success = @$dom->loadHTML('<?xml encoding="utf-8" 

' . $html);
?>

Using the HTML5 library seems to work correctly (it is what Html::load() uses internally).

spuky made their first commit to this issue’s fork.

spuky’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm patch 3 is solving the encoding issue (for me with german Umlauts..)
provided the patch as an MR

e0ipso’s picture

  • e0ipso committed 78495e01 on 1.x authored by spuky
    Issue #3444146 by prudloff, spuky: Wrong entity encoding in story HTML
    
e0ipso’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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