Repository navigation
Notes: Validate reaction keys instead of stripping tags - #86775
adamsilverstein wants to merge 4 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.
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.
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. 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:
Updated as activity occurs, without notifying anyone named here. Add the ⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. As a user I want to be able to create a navigation overlay for a specific navigation block in
|
Link the Core PR for Trac #66695 so the backport check can find it.
| * @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.
this appears to limit the code points to those requiring 4–6 characters, but still lets through code points such as 000a. that’s not problematic, but lets certain syntax forms through while rejecting others when they refer to the same code point.
if the goal is a fast rejection of strings containing unallowed characters, strspn() can be used, and then the only additional check would be inside the foreach for empty spans
if ( strlen( $value ) !== strspn( $value, '-01234567789abcdef' ) ) {
return false;
}
foreach ( explode( '-', $value ) as $hex ) {
$code_point = hexdec( $hex );
if ( '' === $hex || $code_point > 0x10FFFF || ( ... ) ) {
return false;
}
}
return true;nothing significant, but it leaves the PCRE in an awkward spot because it rejects some values which are allowed as syntactical variations, while it allows some forms that may not be expected.
making the PCRE tighter would involve [1-9a-f][0-9a-f]{3,5} to ensure there aren’t leading zeros. relaxing it would be pointless compared to strspn() which performs the check with less complexity and zero allocation.
fun fact! \A and \Z do what I think you are looking for here with the combination of $ and /D. they always work. I have found the PCRE docs way more useful than the PHP docs for the preg_ functions too. anchors and simple assertions
| // Rows written outside this controller may hold anything. | ||
| if ( ! is_string( $slug ) || ! self::is_reaction_key( $slug ) ) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
first thought: is it important to reject values like 1F170 vs. 1f170?
second thought: if this were self::parse_reaction_key() then the trimming and normalization and rejection could all happen in that method.
$reaction_key = self::parse_reaction_key( $slug );
if ( null === $reaction_key ) {
continue;
}
// now $reaction_key is lowercase, trimmed, and fully-normative
Claude Code wrote this up after working through the review feedback on #83169:
AI Use
Claude Code wrote the code, the tests and this description while I was working through review feedback with it. I will review and test.
Session: https://claude.ai/code/session_018vwYjVcDMRyJisiSbUUeky