- 🇩🇪Germany internetter Erfurt, Thüringen
I discovered other problems with rext export of views and image urls. Perhaps it is related:
- https://www.drupal.org/project/rest_views/issues/3176391 🐛 Image links with multiple query parameters have ampersand encoded Fixed
- https://www.drupal.org/project/svg_image/issues/3337927#comment-14898139 🐛 Image links with multiple query parameters have ampersand encoded in REST view Fixed
There was an encoding of parameter ampersand "&" as "\u0026amp;" for multiple parameter urls from image url formatter (using of focal_point).
- Status changed to Needs review
over 2 years ago 12:36pm 28 April 2023 - last update
over 2 years ago 29,366 pass - 🇩🇰Denmark ressa Copenhagen
Thanks @RichardDavies! Your patch works perfectly in Drupal 10, leaving single quotes (
') be, and the output a lot cleaner. Before and after:-
"name": "C\u00f4te d\u0026#039;Ivoire", "name": "Côte d'Ivoire" -
"name": "Pes\u00e4pallo", "name": "Pesäpallo"
Also, much cleaner looking HTML (before and after):
-
"title": "Facts about C\u00f4te d\u0026#039;Ivoire" "title": "Facts about Côte d'Ivoire" -
"field_body": "\u003Ch2\u003E1. Here are some facts\u003C\/h2\u003E ..." "field_body": "<h2>1. Here are some facts<\/h2> ..."
There's also the related issue 🐛 single quote character not escaped in REST output Active about single quotes (
') which I believe don't need to be HTML encoded into', since single quotes don't need escaping because proper JSON output is in double quotes.Should it be looked at here, or in the other issue?
I am attaching a re-rolled patch for Drupal 10.1, since I have bad experiences with re-basing Drupal core MR's in Drupal's Gitlab. Also, this patch can then be used as a patch in Composer, since it is static.
-
- 🇩🇰Denmark ressa Copenhagen
Also, fixing 🐛 Allow JSON format when "Accepted request formats" is not defined Active would get REST and Views export in a great state, working out-of-the-box.
- Status changed to Needs work
over 2 years ago 3:43am 30 April 2023 - 🇺🇸United States smustgrave
Can the issue summary be updated to include the proposed resolution.
Also a test showing the problem will be needed please
Thanks!
- 🇩🇰Denmark ressa Copenhagen
Thanks for reviewing it @smustgrave. I would also be interested in a description of what the regex actually does. @RichardDavies: Perhaps you can help with this?
- 🇩🇰Denmark ressa Copenhagen
I also now see that the preview is still escaped, so we probably should do the same there? I'll add the tasks in the issue summary.
- 🇺🇸United States RichardDavies Portland, Oregon
@ressa The regex searches the $output string for all occurrences of \\uXXXX where X is a hexadecimal character consisting of a digit 0-9 or letter A-F (case insensitive). e.g. \\u0026
For each match that it finds, it uses the mb_convert_encoding() function to convert that character from one encoding to another encoding. Then any double quote characters (") are prefixed with a slash character (\) so that they're properly escaped according to the JSON string requirements.
- 🇩🇰Denmark ressa Copenhagen
Thanks @RichardDavies! Both for working on this solution, and explaining the regex. I have added it in the Issue Summary.
- 🇫🇷France nicolasgraph Strasbourg
Patch #86 causes malformed UTF-8 characters for emojis.