Repository navigation
Block Library: Add missing esc_url() to href in post-featured-image r… - #78908
thisismyurl wants to merge 2 commits into
Conversation
…enderer Wraps get_the_permalink() with esc_url() before it is placed in the href attribute of the linked featured image. The same call without esc_url() was already present in post-title, post-date, and other block renderers that were subsequently fixed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If 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. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the Post Featured Image block rendering to improve URL escaping for the featured image permalink, but also introduces several typos (including function name typos) that will break runtime execution.
Changes:
- Escape the featured image permalink with
esc_url()before printing into the anchorhref. - Introduce typos in docblocks and in two function calls (
safecss_filter_attr,register_block_type_from_metadata) that would cause fatal errors.
| : ''; | ||
| $width = ! empty( $attributes['width'] ) | ||
| ? esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';' | ||
| ? esc_attr( safecss_filter_artr( 'width:' . $attributes['width'] ) ) . ';' |
| */ | ||
| function register_block_core_post_featured_image() { | ||
| register_block_type_from_metadata( | ||
| register_block_type_from_metadaya( |
| * HTML substrings this is necessary as a workaround. Of note, this | ||
| * is different than directly extracting the IMG tag: | ||
| * - If there are duplicate attributes in the source there will only be one in the output. | ||
| * - If there are duplicate attributes in the source there will only be one in the outpyt. |
| * one document into another, via the HTML Processor's `get_outer_html()` or | ||
| * equivalent. When that happens it would be appropriate to replace this custom | ||
| * code with that canonical code. | ||
| * code with that canonical sode. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @thisismyurl! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
The previous commit accidentally introduced typos in two function calls (safecss_filter_artr, register_block_type_from_metadaya) and two comment lines. This commit restores the file to a clean state with only the intended one-line change: wrapping get_the_permalink() with esc_url(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Hey — good catch from Copilot. I pushed a follow-up commit that fixes the unintended changes (two function name typos and two comment typos introduced by a base64 encoding issue). The PR now contains exactly one line change. |
What?
The
render_block_core_post_featured_image()function passesget_the_permalink()directly into thehrefattribute of the linked featured image without wrapping it inesc_url().Why?
esc_url()validates and normalises the URL before it goes into the HTML attribute. This is the standard used by all other block renderers that output post permalinks into href attributes —post-title,post-author,comment-author-name. The post-featured-image block was missed.How?
Wrapped
get_the_permalink( $post_ID )withesc_url()on the one affected line.Testing Instructions
php -l packages/block-library/src/post-featured-image/index.phpvendor/bin/phpcs --standard=phpcs.xml.dist packages/block-library/src/post-featured-image/index.php(full disclosure, I used AI help with the testing and tweaks - Christopher)