Skip to content

Conversation

@kraftbj
Copy link
Contributor

@kraftbj kraftbj commented Aug 20, 2025

Fixes HOG-301

The WP_HTML_Tag_Processor will construct with any value passed to it, but get_updated_html is type-restricted to only returning a string. This will lead to a runtime fatal.

While this is something Core can (should?) address, we can save a lot of work by just returning early a value that we won't be able to do anything with.

The Core issue is proposed and patched via https://core.trac.wordpress.org/ticket/63854

Proposed changes:

  • If a non-string is passed to filter_the_content, early return the passed value.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

.

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

  • Run Image_CDN::filter_the_content(null); before and after this patch.
  • Before: runtime fatal.
  • After: no fatal, returns null.

@kraftbj kraftbj added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Review This PR is ready for review. labels Aug 20, 2025
@kraftbj kraftbj self-assigned this Aug 20, 2025
@github-actions github-actions bot added [Feature] Photon aka "Image CDN". Feature developed in the Image CDN package and shipped in multiple plugins [Package] Image CDN [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels Aug 20, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Aug 20, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

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:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: September 2, 2025
    • Code freeze: September 1, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Boost plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 20, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the update/jetpack/no-null-content-cdn-HOG-301 branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/jetpack/no-null-content-cdn-HOG-301

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@jp-launch-control
Copy link

jp-launch-control bot commented Aug 20, 2025

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/image-cdn/src/class-image-cdn.php 376/509 (73.87%) 0.10% 0 💚

Full summary · PHP report · JS report

Co-authored-by: Weston Ruter <[email protected]>
Copy link
Contributor

@tbradsha tbradsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For malformed content, I think we should return an empty string, as that's the proper signature of functions that use the filter. Otherwise we're just passing along the wrong data type to the next function that hooks into the filter.

@westonruter
Copy link
Contributor

@tbradsha like this, for example?

/**
 * Filters foo.
 *
 * @param string|mixed $foo Foo.
 * @return string Foo.
 */
function filter_foo( $foo, int $post_id ): string {
	if ( ! is_string( $foo ) ) {
		// Because plugins do bad things.
		$foo = '';
	}

	 // Filtering logic goes here.

	 return $foo;
}
add_filter( 'foo', 'filter_foo', 10, 2 );

@tbradsha
Copy link
Contributor

tbradsha commented Aug 21, 2025

like this, for example?

Yep, precisely. Since the widget_text filter is documented to pass a string, we should:

  • check for a string type, but allow for any type, since
    1. the content could be filtered in third-party code to a bad type prior to getting to the function
    2. there could be a third-party apply_filter that passes a bad type
  • return a string type (be it an empty or fallback string), since that prevents similar errors for the next function that's hooked into the filter.

Copy link
Contributor Author

kraftbj commented Aug 21, 2025

I was torn between passing through malformed vs returning an empty string instead. Hearing y'all, I'll update the code and tests to return '' vs passthrough.

Copy link
Contributor

@tbradsha tbradsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@kraftbj kraftbj merged commit 00e4a14 into trunk Aug 22, 2025
77 checks passed
@kraftbj kraftbj deleted the update/jetpack/no-null-content-cdn-HOG-301 branch August 22, 2025 15:07
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Photon aka "Image CDN". Feature developed in the Image CDN package and shipped in multiple plugins [Package] Image CDN [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests [Type] Bug When a feature is broken and / or not performing as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants