Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitization: clone node before importing #12160

Merged
merged 2 commits into from
Aug 25, 2022
Merged

Conversation

swissspidy
Copy link
Collaborator

Context

While looking at #12159 I found another issue related to the AMP output sanitization, where some text content was completely missing.

I then realized it was because of the Sanitization_Utils::change_tag_name() method (used via Sanitization_Utils::use_semantic_heading_tags(). That util uses DomDocument::importNode(), which calls DomDocument::importNode() on a DomNodeList, which is not a simple array but actually an IteratorAggregate.

So when importing a node in a loop like that, it directly modifies the list, missing subsequent children

Summary

This PR addresses this by cloning the child nodes before importing them, making sure the DomNodeList traversal works as expected.

Relevant Technical Choices

To-do

N/A

User-facing changes

N/A

Testing Instructions

  • This is a non-user-facing change and requires no QA

This PR can be tested by following these steps:

Reviews

Does this PR have a security-related impact?

No

Does this PR change what data or activity we track or use?

No

Does this PR have a legal-related impact?

No

Checklist

  • This PR addresses an existing issue and I have linked this PR to it in ZenHub
  • I have tested this code to the best of my abilities
  • I have verified accessibility to the best of my abilities (docs)
  • I have verified i18n and l10n (translation, right-to-left layout) to the best of my abilities
  • This code is covered by automated tests (unit, integration, and/or e2e) to verify it works as intended (docs)
  • I have added documentation where necessary
  • I have added a matching Type: XYZ label to the PR

Fixes #

@swissspidy swissspidy added Type: Bug Something isn't working Group: WordPress Changes related to WordPress or Gutenberg integration AMP Output Issues related to AMP output and validation Pod: WP labels Aug 23, 2022
@googleforcreators-bot
Copy link
Collaborator

googleforcreators-bot commented Aug 23, 2022

Plugin builds for e9470a3 are ready 🛎️!

@swissspidy swissspidy merged commit 9fd0a6a into main Aug 25, 2022
@swissspidy swissspidy deleted the fix/sanitization-cloneNode branch August 25, 2022 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AMP Output Issues related to AMP output and validation Group: WordPress Changes related to WordPress or Gutenberg integration Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants