Repository navigation
Conversation
Escaping can't make these characters valid, so one bad value made a whole sitemap file unparseable. Clean text values in all three buffer types before writing them.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 2 files.
|
Matching bytes in scrubbed text doesn't depend on PCRE's Unicode support. Image, video and news values take a separate path in the DOMDocument buffer that the test didn't cover.
Fixes #55582
Proposed changes
U+FFFD, using core'swp_scrub_utf8(). It also makes the file unparseable.If a URL really contains one of these characters, the cleaned-up URL may 404 or, rarely, match a different file. That affects one entry instead of the whole file.
Core doesn't have a function that does all of this.
wp_scrub_utf8()fixes malformed UTF-8 but keeps these characters.wp_kses_no_null()keepsU+FFFEandU+FFFF, and by default also removes some valid text.esc_xml()keeps control characters, and its escaping would be doubled by the sitemap writers.The reported failure depends on the server's libxml2 version. 2.9.14 writes control characters as is, while 2.15.2 (in the current dev container) replaces them with
�. 2.15.2 still writesU+FFFEand malformed UTF-8 as is, and still cuts values off at a null byte. The new test compares the parsed values, so it also fails without the fix on newer versions.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Use a site whose PHP uses libxml2 2.9.x to see the reported failure. Check with
php -r 'echo LIBXML_DOTTED_VERSION;'.wp post meta update <attachment_id> _wp_attached_file "2019/07/test$(printf '\001').jpg"wp jetpack sitemap rebuild --purge.curl -s https://example.com/image-sitemap-1.xml | xmllint --noout -, using your site's URL.PCDATA invalid Char value 1. On this branch, it passes. Both images are listed, and the changed one ends intest.jpg.add_filter( 'jetpack_sitemap_use_xmlwriter', '__return_false' );, then rebuild and parse again.I ran these steps on WordPress 7.1.5 with PHP 8.4.27 and libxml2 2.9.14, parsing with PHP instead of
xmllint. XMLWriter failed before the fix and passed after it. It also handled a post title containingU+0001in the news sitemap (checked after the fix only). I only checked the DOMDocument writer after the fix. The string fallback is covered by unit tests only.