-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Update cleanForSlug() to remove additional non-word characters #21007
Conversation
Size Change: +9 B (0%) Total Size: 857 kB
ℹ️ View Unchanged
|
For posterity's sake, the reference implementation: https://github.com/WordPress/wordpress-develop/blob/5.3.2/src/wp-includes/formatting.php#L2145 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a reasonable change to me.
Do you know of any usage of cleanForSlug
which may have relied on this behavior, broken as it may have been, for which these changes might cause some unforeseen incompatibility?
If the idea is for it to adhere to core's equivalent treatment of sanitize_title
, it could be a good idea (perhaps separately from here) to include some or all of its test cases:
- https://github.com/WordPress/wordpress-develop/blob/master/tests/phpunit/tests/formatting/SanitizeTitleWithDashes.php
- https://github.com/WordPress/wordpress-develop/blob/master/tests/phpunit/tests/formatting/SanitizeTitle.php
- https://github.com/WordPress/wordpress-develop/blob/master/tests/phpunit/tests/formatting/RemoveAccents.php
I have another branch I started for duplicating |
Should we add a note in the changelog of the url package? It looks like it can be merged otherwise. |
Description
This updates the
cleanForSlug()
function to remove punctuation characters that would get removed bysanitize_title()
upon publishing.This fixes the original issue from #12907 regarding punctuation in the slug. It doesn't resolve the related issues referenced there that were opened for characters in other languages (such as German and Danish) not being converted properly. If we merge this and close #12907, we may want to reopen one of those that was closed as a duplicate in order to keep a more accurate record.
On investigating removing other punctuation, I realized
sanitize_title()
allows underscores in slugs, so I adjusted the function to allow those, but to remove any other non-hyphen punctuation. I also removed thetoLower
dependency and switched to.toLowerCase()
How has this been tested?
Used identical strings with a variety of characters in the classic editor and in the current editor to test how they compared. Also updated the unit tests to reflect the new characters that should be removed.
Screenshots
Here is a sample string in the classic editor:
![Screen Shot 2020-03-18 at 1 14 05 PM](https://user-images.githubusercontent.com/4267290/77019808-1515a500-6958-11ea-8d80-7f4631c70068.png)
Vs the block editor after this change:
![Screen Shot 2020-03-18 at 1 15 26 PM](https://user-images.githubusercontent.com/4267290/77019822-21016700-6958-11ea-8ccf-c146e73fd8ec.png)
Checklist: