Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove HTML entities from post slug during cleaning #68813

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

devansh016
Copy link
Contributor

@devansh016 devansh016 commented Jan 21, 2025

What?

This PR ensures that HTML entities, such as &, are properly decoded when generating post slugs. It modifies the getEditedPostSlug selector to decode entities in post titles before cleaning them for slug creation.

Why?

The current implementation adds unnecessary HTML entities like amp to slugs when saving drafts. This behavior can cause confusion and lead to unnecessarily long or SEO-unfriendly URLs. For example, a draft title containing & becomes /ampersand-amp-and/, but upon publishing, it correctly becomes /ampersand-and/. This PR fixes the inconsistency by decoding HTML entities before cleaning the slug.

Fixes #62543

How?

  • Added decodeEntities from @wordpress/html-entities to the getEditedPostSlug selector.
  • Updated the slug-cleaning process to decode HTML entities in the post title before passing it to cleanForSlug.

Code changes are minimal and located in packages/editor/src/store/selectors.js.

Testing Instructions

  1. Go to Settings > Permalinks and set the permalink structure to "Post name".
  2. Create a new post with a title containing special characters, e.g., Ampersand & And.
  3. Save the post as a draft.
  4. Check the generated URL in the editor sidebar.
    • Before: /ampersand-amp-and/
    • After: /ampersand-and/
  5. Publish the post and confirm the URL remains /ampersand-and/.

Testing Instructions for Keyboard

Screenshots or screencast

Before After

Copy link

github-actions bot commented Jan 21, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: devansh016 <devansh2002@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: Soean <soean@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: 2ndkauboy <kau-boy@git.wordpress.org>
Co-authored-by: marcarmengou <marc4@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Package] Block editor /packages/block-editor labels Jan 22, 2025
@Mamaduka
Copy link
Member

Thanks for contributing, @devansh016!

The referenced issue has a PR (#62549) with an ongoing review process. Just FYI.

@devansh016
Copy link
Contributor Author

Thanks for contributing, @devansh016!

The referenced issue has a PR (#62549) with an ongoing review process. Just FYI.

Thanks, @Mamaduka! I’ve reviewed the other PR. My approach is slightly different, and the previous PR has been inactive for the past couple of months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The & symbol becomes amp in the draft URL
2 participants