-
Notifications
You must be signed in to change notification settings - Fork 846
Map block: Prevent PHP fatal when content is empty #41583
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
Conversation
|
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 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Follow this PR Review Process:
Still unsure? 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 1 file.
|
If the Map block receives empty content, it results in a PHP fatal. This PR returns early in that scenario.
Proposed changes:
This was discovered while monitoring a deploy:
Prior to PHP 8,
DOMDocument::loadHTML()would throw a deprecation notice if the source string is empty; now it gives a fatal (docs).There's no way to reliably prevent
$contentfrom being empty, given there's anapply_filters()just before which could be used by any third-party code.At first I wasn't sure if it was safe to just return, but looking further in code that'd be precisely what it does if
$containeris not truthy, which would always be case since theDOMXPath::querywould not find the path in question with empty content anyway. I believe another solution would be to throw a dummy<div></div>into$contentshould it be empty, but that seems more hackish.Anyway, I'm fairly confident this restores the same behavior seen in PHP <8.
Note: the line in question did have a suppression before with
@added in d9492d1, but it's unclear from the PR (#13405) or the commit message if this or some other scenario warranted it. As such, I'm leaving it in place for now. There are also somelibxml_use_internal_errors()calls, but those would be applicable for normal parsing errors too, so should stay.Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
I'm not sure how to reproduce this best...check my logic above?