Skip to content

Conversation

@tbradsha
Copy link
Contributor

@tbradsha tbradsha commented Nov 26, 2025

Closes MONOREP-268

See MONOREP-129 and further discussion in p1763997995289799-slack-C05Q5HSS013.

This is a best-effort application of proper flags for json_encode() and wp_json_encode().

It also includes some cleanup of PHP 5.2 compatibility (JSON.parse(decodeURIComponent())), which was a workaround for when the flags we now use did not exist.

I've tagged for review a few teams whose plugins I know I touched.

Proposed changes:

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?

Testing instructions:

  • Go to '..'

@tbradsha tbradsha requested review from a team November 26, 2025 21:40
@tbradsha tbradsha self-assigned this Nov 26, 2025
@tbradsha tbradsha added the [Status] Needs Review This PR is ready for review. label Nov 26, 2025
@tbradsha tbradsha requested a review from a team as a code owner November 26, 2025 21:40
@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 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 or WordPress.com Site Helper), and enable the fix/audit_json_encode_flags_part_trois branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/audit_json_encode_flags_part_trois

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

@github-actions github-actions bot added [Feature] WooCommerce Analytics [Focus] Compatibility Ensuring our products play well with third-parties [Plugin] Automattic For Agencies Client [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Classic Theme Helper Plugin [Plugin] Debug Helper Debug Tools plugin [Plugin] Inspect [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Starter Plugin [Plugin] Super Cache A fast caching plugin for WordPress. [Plugin] VaultPress [Plugin] Wpcomsh [Tests] Includes Tests E2E Tests labels Nov 26, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 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: December 2, 2025

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


Debug Helper 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.


Vaultpress 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.


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.


Starter Plugin 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.


Protect 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.


Super Cache 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.


Inspect 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.


Wpcomsh plugin:

  • Next scheduled release: Atomic deploys happen twice daily on weekdays (p9o2xV-2EN-p2)

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


Automattic For agencies client 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.


Classic Theme helper plugin 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.

@jp-launch-control
Copy link

jp-launch-control bot commented Nov 26, 2025

Code Coverage Summary

Cannot generate coverage summary while tests are failing. 🤐

Please fix the tests, or re-run the Code coverage job if it was something being flaky.

Full summary · PHP report · JS report

@tbradsha
Copy link
Contributor Author

The change that caused this is in projects/plugins/jetpack/extensions/blocks/story/story.php. Honestly, I think something like this would be even better:

esc_attr( wp_json_encode( $settings, JSON_HEX_AMP | JSON_UNESCAPED_SLASHES ) )

However, I'm not familiar enough with the expectation of blocks.

I can reproduce the failure locally with $ jetpack docker phpunit jetpack -- --filter=Story_Block_Test:

1) Story_Block_Test::test_server_side_rendering_based_on_serialized_fixtures
The results of render_block for jetpack/story called with serialized markup from jetpack__story.serialized.html do not match the server-rendered fixture: jetpack__story.server-rendered.html

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'...ry--1" data-settings="{"slides":[]}">\n
+'...ry--1" data-settings="{"slides":[]}">\n
 			<div class="...'

/usr/local/src/jetpack-monorepo/projects/plugins/jetpack/tests/php/extensions/blocks/Story_Block_Test.php:128

I'm not sure the proper way to fix this, nor whether this is a superficial issue that just needs something on the test side changed or one that would cause bigger issues.

Copy link
Contributor

@coder-karen coder-karen left a comment

Choose a reason for hiding this comment

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

Classic Theme Helper plugin changes look valid to me, thanks for updating all of this code.

I'm not sure the proper way to fix this, nor whether this is a superficial issue that just needs something on the test side changed or one that would cause bigger issues.

From what I can see, even though render_block in story.php prints the data-settings attribute with possible entity differences, view.js reads data-settings via getAttribute, then JSON.parses it. With json.parse, those entities are then normalized again.
While I'm not too sure what best practice would be generally with blocks in terms of entity expectations, I don't see anything else in the block code that uses the raw, pre-parsed attribute.
In the tests however the full HTML output is compared as a raw string to the fixture, so entity form differences will fail the assertion.
It appears as though updating the test is all that is needed. It may be worth a second opinion though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] AI Chat [Block] Donations [Block] Map [Block] Paid Content aka Premium Content [Block] Podcast Player [Block] Story [Boost Feature] Cloud CSS [Boost Feature] Lcp [Boost Feature] Page Cache E2E Tests [Feature] Ad [Feature] Carousel A fullscreen modal appearing when clicking on an image in a gallery or tiled gallery. [Feature] Comments [Feature] Extra Sidebar Widgets [Feature] Google Fonts [Feature] Infinite Scroll [Feature] Sharing Post sharing, sharing buttons [Feature] Shortcodes / Embeds [Feature] Subscriptions All subscription-related things such as paid and unpaid, user management, and newsletter settings. [Feature] VideoPress A feature to help you upload and insert videos on your site. [Feature] WooCommerce Analytics [Focus] Compatibility Ensuring our products play well with third-parties [Plugin] Automattic For Agencies Client [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Classic Theme Helper Plugin [Plugin] Debug Helper Debug Tools plugin [Plugin] Inspect [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Starter Plugin [Plugin] Super Cache A fast caching plugin for WordPress. [Plugin] VaultPress [Plugin] Wpcomsh [Status] Needs Review This PR is ready for review. [Tests] Includes Tests [Type] Janitorial

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants