Repository navigation
Fix non-ASCII characters in scripts of fetched HTML pages - #9384
Merged
Merged
Conversation
To add a <base> to a fetched HTML page, enforceHtmlBase() re-serialises it with libxml2 saveHTML(). For a whole document, libxml2 2.9 only knows the charset from <meta http-equiv="Content-Type">: with <meta charset="UTF-8"> or a byte order mark, it writes every non-ASCII character as an HTML entity. In text that is harmless, but inside <script> entities are not decoded, so e.g. the JSON read by HTML + XPath + JSON feeds gets "Wall Street’s" instead of "Wall Street’s", which then shows in titles. UTF-8 documents are now serialised node by node, which writes UTF-8. Other charsets keep the previous output.
shcheglovnd
marked this pull request as ready for review
October 2, 2026 02:01
Frenzie
reviewed
Oct 2, 2026
Frenzie
reviewed
Oct 3, 2026
# Conflicts: # tests/app/Utils/httpUtilTest.php
Contributor
Author
|
Sorry for the delay with PR, I am going to update and merge it today |
Contributor
Author
|
Oh, right, the merge is only possible by the maintainer. @Alkarex ptal when you have time. Thanks. |
Alkarex
approved these changes
Oct 31, 2026
Member
|
Thanks 👍🏻 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed in this pull request:
<script>of fetched HTML pages, e.g. titles of an HTML + XPath + JSON feed showingWall Street’sinstead ofWall Street’s.<base>,enforceHtmlBase()re-serialises the page with libxml2saveHTML(). For a whole document, libxml2 (2.9.14 in our Debian image) only knows the charset from<meta http-equiv="Content-Type">. With the more common<meta charset="UTF-8">, or with the byte order mark thatenforceHttpEncoding()adds, it writes every non-ASCII character as an entity. That is harmless in text, but inside<script>entities are not decoded, so the JSON embedded in the page (e.g. Next.js__NEXT_DATA__) is changed.How to test the feature manually:
https://www.wsj.com/newsletters/the-10-point, with XPath to JSON//script[@id='__NEXT_DATA__'], item0.props.pageProps.recentEditionArticles, titleheadline, URIarticleUrl.’. After:’.img/@alt) shows’before and after.Tested on the 1.30.0 Docker image (PHP 8.4.24, libxml2 2.9.14) with the page above, for both feed types, before and after the change. The new unit test fails without the change for
<meta charset>and for a byte order mark, and passes with it; the whole test suite, PHPStan and PHPCS pass.Pull request checklist:
Additional information can be found in the documentation.