-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Save DOMDocument node instead of root + str_replace #25020
Conversation
We wrapped block HTML in some tags to ensure the DOMDocument parses it correctly, then unwrapped it again with str_replace after using `saveHTML`. The `saveHTML` method accepts an optional argument that is the dom node to output a subset of the document: https://www.php.net/manual/en/domdocument.savehtml.php Rather than calling `str_replace` on the entire document to get the unwrapped block HTML, invoke `saveHTML` on the block root to get the unwrapped HTML. This prevents some additional newlines from being appended to the output which was observed when running core block tests with Gutenberg activated.
Size Change: +30 B (0%) Total Size: 1.17 MB
ℹ️ View Unchanged
|
Looking good. @sirreal Is there any chance we can modify the string we use in unit tests to cover the problematic newlines case? gutenberg/phpunit/class-block-supported-styles-test.php Lines 120 to 126 in 668182c
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get this into 8.9. We'll add unit test coverage afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, now even with test coverage!
This PR caused a regression in the Categories block when a dropdown is displayed. See #25026. |
Description
We wrapped block HTML in some tags to ensure the DOMDocument parses it
correctly, then unwrapped it again with str_replace after using
saveHTML
.The
saveHTML
method accepts an optional argument that is the dom nodeto output a subset of the document:
https://www.php.net/manual/en/domdocument.savehtml.php
Rather than calling
str_replace
on the entire document to get theunwrapped block HTML, invoke
saveHTML
on the block root to get theunwrapped HTML.
This prevents some additional newlines from being appended to the
output which was observed when running core block tests with Gutenberg
activated.
How has this been tested?
Manual and automated testing of some dynamic blocks.
Types of changes
Internal.
Checklist: