Skip to content

Conversation

enejb
Copy link
Member

@enejb enejb commented Aug 23, 2025

This PR fixed the endocing issue by making sure that v2 version of the encoding gets.

The problem was that in V2 unicode strings such as special characters (emojies or languages such as japanse )
stripped the / from the content. This made it so that we don't know that the characters were unicode when the conversion happened in decode_json.

Fixes FORMS-271

Proposed changes:

  1. Switch the default version to v3 and add a test to make sure that the encoding works as expected.
  2. Wrap the content with addslashes() before saving the content in V3
  3. Deal with V2 string field values in a way that we decode content properly again. (We assume the content doesn't have the slashes) + Added tests.

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

p1755930976939539-slack-C086RGTJT1D

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

No

Testing instructions:

Do the tests pass?

On a post with special characters. Do you see the content as expected now?

@enejb enejb requested a review from a team August 23, 2025 22:58
@enejb enejb added [Status] Needs Review This PR is ready for review. [Package] Forms labels Aug 23, 2025
Copy link
Contributor

github-actions bot commented Aug 23, 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 fix/decoding-issue branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/decoding-issue

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

Copy link
Contributor

github-actions bot commented Aug 23, 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!

@github-actions github-actions bot added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Aug 23, 2025
Copy link

jp-launch-control bot commented Aug 23, 2025

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/contact-form/class-feedback.php 452/463 (97.62%) -0.36% 2 ❤️‍🩹
projects/packages/forms/src/contact-form/class-feedback-field.php 118/123 (95.93%) 16.34% -15 💚

Full summary · PHP report · JS report

@enejb enejb added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Aug 24, 2025
@enejb enejb requested a review from Copilot August 25, 2025 01:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

@CGastrell CGastrell left a comment

Choose a reason for hiding this comment

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

Seems to work fine, but I'm not sure I have an actual case to test. I tried adding weird characters and tilde things on the fields and responses, it all worked out.

Tests also pass.

I can't be sure how to test one of the real cases. Maybe we can get some feedback post content and paste it?

@enejb
Copy link
Member Author

enejb commented Aug 26, 2025

@CGastrell The way to test it would be to revert back to the point where we were creating V2 versions of the feedback.
save some of them with special characters. Notice that they are broken.

Then load up this PR and notice that you see them now.

@enejb enejb force-pushed the fix/decoding-issue branch 2 times, most recently from d1ed69f to 679bd24 Compare August 27, 2025 21:37
public static function normalize_unicode( $string ) {
// Case 1: JSON-style escapes, e.g. "\u003cstrong\u003e" or "\ud83d\ude48"
if ( strpos( $string, '\u' ) !== false ) {
$decoded = json_decode( '"' . $string . '"' );
Copy link
Contributor

Choose a reason for hiding this comment

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

we could extract

			if ( $decoded !== null && json_last_error() === JSON_ERROR_NONE ) {
				return $decoded;
			}```

into it's own method as we do the same in the following if?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call. We can do this in a follow up PR.

CGastrell
CGastrell previously approved these changes Sep 2, 2025
Copy link
Contributor

@CGastrell CGastrell left a comment

Choose a reason for hiding this comment

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

Couldn't make it fail. Tried with bogus words and country flags in unicode. Worked well.

lezama
lezama previously approved these changes Sep 2, 2025
Adds normalization for Unicode characters in feedback field values, especially for legacy and v2 feedback formats that may contain escaped or raw Unicode sequences. Updates Feedback_Field and Feedback classes to support this, introduces new parsing logic for v3 feedback, and adds comprehensive tests to ensure correct handling of special characters and emojis.
@enejb enejb force-pushed the fix/decoding-issue branch from 679bd24 to 1fd0210 Compare September 2, 2025 19:54
@enejb enejb dismissed stale reviews from lezama and CGastrell via e4dfa9d September 2, 2025 20:11
@enejb enejb merged commit 1afa590 into trunk Sep 2, 2025
67 checks passed
@enejb enejb deleted the fix/decoding-issue branch September 2, 2025 20:31
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Contact Form [Package] Forms [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.

4 participants