Repository navigation
REST API: Compare note reaction keys exactly instead of stripping tags - #15985
adamsilverstein wants to merge 10 commits into
Conversation
A reaction row whose content is not a key should be left out of the summary, and markup around a key should be rejected on create. See #66695.
wp_strip_all_tags() let any stored content through as a summary key and folded "<b>2764</b>" into "2764". Check the shape of a stored key and compare validated keys exactly. See #66695.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| * | ||
| * A key is one or more Unicode scalar values in lowercase hex, joined | ||
| * by `-`. The shape is checked, not the curated set, so a reaction | ||
| * stays readable if the set changes. |
There was a problem hiding this comment.
this sounds like AI speak, and answers a question that seems unlikely to be asked. maybe the entire thing could be tersely and more-helpfully described, though I know that others are sure to have different expectations than me.
/**
* Determines if a given value represents a valid reaction key.
*
* Reaction keys are described by a sequence of one or more Unicode
* Scalar Values joined by a hyphen (U+2D).
*
* @since 7.2.0
*
* @param string $value Potentially contains a valid reaction key.
* @param bool Whether the given value comprises a well-formed reaction key.
*/There was a problem hiding this comment.
Good suggestion, thanks
| * @return bool True for a well-formed key. | ||
| */ | ||
| private static function is_reaction_key( string $value ): bool { | ||
| if ( 1 !== preg_match( '/^[0-9a-f]{4,6}(?:-[0-9a-f]{4,6})*$/D', $value ) ) { |
There was a problem hiding this comment.
just realized I am confused because there are two PRs 😆
https://github.com/WordPress/gutenberg/pull/86775/changes#r4633747523
There was a problem hiding this comment.
right this is the backport, its probably better to keep all the feedback on that Gutenberg PR, then I can make sure the backport is synced accordingly.
There was a problem hiding this comment.
I will try and remember, thank you!
The pattern accepted several spellings of one code point (`02764` next to `2764`). Accept a single spelling per code point - lowercase hex, zero-padded to four digits - so equal reactions always share a summary bucket, and drop the regular expression for a span check. See #66695.
Describe the rows wpdb returns so the summary code passes PHPStan at level 10, which makes the is_string() guard redundant. See #66695.
Keys are no longer stripped of tags, so each group of rows maps to its own key and nothing is left to add up. See #66695.
Since r65750 the summary only counts curated keys, an allow list that covers everything the shape check guarded. Compare stored content to the curated keys exactly and remove the helper. See #66695.
answering here instead of the Gutenberg patch since you asked here. that’s a fair choice and I don’t see an obvious problem with it, though it does contradict the previously-worded description
it’s probably likely we will expand this set, and I suspect people will end up opening it first to all Unicode code points, and then restrict it to valid extended grapheme clusters, and then expand it to slugs like if that’s the case then the parsing aspect would still be valuable, but that can be addressed when the functionality changes in the future. at a minimum, however, since we are talking about removing the runtime guards against inputs whose contents cannot always be trusted, it would be worth noting somewhere that when the rules change, additional parsing and/or validation should apply. the only particular case that’s really worth ensuring is that we don’t invite a future change to introduce values that will be invalid if nobody remembers to update the corresponding code. I’m trusting you can make these calls and not trying to hide a demand that you add comments or change things. you would know better than I do if there’s a data-flow gap or reasonable estimation that untrusted comment content could reach this in a way that breaks things in a way that matters. |
Exact comparison against the fixed list is the only guard on request and stored reaction content. Note that at both comparisons so widening the set does not leave unvalidated keys behind.
Claude Code (Fable 5.2) cut this PR down after r65750 landed, updated description below:
Trac ticket: https://core.trac.wordpress.org/ticket/66695
AI Use
Claude Code (Fable 5.2) wrote the code, the tests and this description. I will review and test.
🤖 Generated with Claude Code
https://claude.ai/code/session_018vwYjUFvgZaeA8cQrCjN2u