Post Title block should use esc_url() #53981
Merged
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.
What?
This PR adds URL escaping to the html output rendered by the Post Title block. It is not an issue of security, only of code quality.
Why?
Good WP coding standards require the use of
esc_url()
when outputting a URL. This applies even to URLs generated by core functions such asget_the_permalink()
; see for reference the Twenty Twenty One theme, which does exactly that:https://github.com/WordPress/twentytwentyone/blob/ba9f20cad89163761185c0467b346ba42541ae22/template-parts/content/content.php#L19
The Post Title block currently fails to escape the URL.
For the record, the Post Title block also fails to escape the title itself; however this is correct behaviour as per the docs: https://developer.wordpress.org/reference/functions/the_title/#more-information. Personally I think that position ought to be reconsidered, but that's a whole other issue, so I have intentionally left it as-is for this PR.
Related: #53838.
How?
The only change in this PR is adding the
esc_url()
call.Testing Instructions
href
in the link tag for the#wp-block-post-title
is correct.Screenshots or screencast