Skip to content

Commit

Permalink
Map block: Prevent PHP fatal when content is empty (#41583)
Browse files Browse the repository at this point in the history
* Return early if content is empty

* Add comment

* Add changelog

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/13180555895

Upstream-Ref: Automattic/jetpack@c02cec5
  • Loading branch information
tbradsha authored and matticbot committed Feb 6, 2025
1 parent 1241c64 commit 0032983
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This is an alpha version! The changes listed here are not final.
- Jetpack SEO: assistant option bubbles border design
- Jetpack SEO: fix state inconsistencies, change effects and use global isBusy suspense flag
- Jetpack Sync: Fixed extracting UTF-8 characters from image alt-text
- Map block: Catch error if content is empty.
- Reader: Update url from /read to /reader
- Reset to-test.md for Jetpack 14.4 release cycle.
- Sync: Full-sync chunking logic dynamic for Woo modules
Expand Down
5 changes: 5 additions & 0 deletions extensions/blocks/map/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ function render_single_block_page() {
/** This filter is already documented in core/wp-includes/post-template.php */
$content = apply_filters( 'the_content', $post->post_content );

// Return early if empty to prevent DOMDocument::loadHTML fatal.
if ( empty( $content ) ) {
return;
}

/* Suppress warnings */
libxml_use_internal_errors( true );
@$post_html->loadHTML( $content ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
Expand Down

0 comments on commit 0032983

Please sign in to comment.