Forms: Guard rating field rendering against non-string values#47971
Merged
Forms: Guard rating field rendering against non-string values#47971
Conversation
Add an is_string() check at the top of get_rating_value() so non-string
$this->value short-circuits to an empty string before the explode('/')
that parses the "rating/max" format. This matches the existing
defensive is_string() pattern already used in render_email_rating() and
in the get_phone_value_with_flag() helper.
Tests cover the web and email rendering contexts (which both route
through get_rating_value()) and pin the existing safe behavior of the
email_html context (which already routed through the guarded
render_email_rating() helper).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Contributor
|
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 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
|
enejb
approved these changes
Apr 8, 2026
Member
enejb
left a comment
There was a problem hiding this comment.
Change make sense. Tests pass. 🚢 it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes FORMS-660
Proposed changes
Feedback_Field::$valueis typed asmixedin the constructor, butget_rating_value()callsexplode( '/', $this->value )directly without guarding against non-string input. Under PHP 8 a non-string argument toexplode()causes a fatal error, which means the rendering pipeline can't gracefully handle anything other than a string in$this->valuefor rating fields.The fix adds an
is_string()check at the top ofget_rating_value()so non-string values short-circuit to an empty string before the parser runs. This matches the existing defensiveis_string()pattern already used in the siblingrender_email_rating()(for the email_html context, which is why that path was already safe) and inget_phone_value_with_flag()(the parallel phone field helper).Other information
get_rating_value()) plus a regression pin for the email_html context (which routes through the already-guardedrender_email_rating()helper).Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
test_rating_field_with_array_value_renders_safely_in_web_contexttest_rating_field_with_array_value_renders_safely_in_email_contexttest_rating_field_with_array_value_renders_safely_in_email_html_context3/5) and verify the success summary, structured email, and HTML email all render the rating correctly (web context shows star/heart structured data, HTML email shows the gold/grey star characters).