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é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.
Comments
Comment #2
prudloff commentedGitLab fails to create the issue fork for some reason so here is a patch.
Comment #3
prudloff commentedTurns 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:' . $html);
?>
Using the HTML5 library seems to work correctly (it is what
Html::load()uses internally).Comment #6
spuky commentedI can confirm patch 3 is solving the encoding issue (for me with german Umlauts..)
provided the patch as an MR
Comment #7
e0ipsoComment #9
e0ipso