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

Allow non-latin characters in slugs #32232

Merged
merged 6 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/editor/src/utils/test/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ describe( 'cleanForSlug()', () => {
expect( cleanForSlug( '/Is th@t Déjà_vu? ' ) ).toBe( 'is-tht-deja_vu' );
} );

it( 'Should allow non-latin characters', () => {
expect( cleanForSlug( 'Καλημέρα Κόσμε' ) ).toBe( 'καλημέρα-κόσμε' );
} );

it( 'Should return an empty string for missing argument', () => {
expect( cleanForSlug() ).toBe( '' );
} );
Expand Down
10 changes: 5 additions & 5 deletions packages/editor/src/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export function getWPAdminURL( page, query ) {
* This replicates some of what sanitize_title() does in WordPress core, but
* is only designed to approximate what the slug will be.
*
* Converts Latin-1 Supplement and Latin Extended-A letters to basic Latin
* letters. Removes combining diacritical marks. Converts whitespace, periods,
* Converts Latin-1 Supplement and Latin Extended-A letters to basic Latin letters.
* Removes combining diacritical marks. Converts whitespace, periods,
* and forward slashes to hyphens. Removes any remaining non-word characters
* except hyphens. Converts remaining string to lowercase. It does not account
* for octets, HTML entities, or other encoded characters.
* except hyphens and underscores. Converts remaining string to lowercase.
* It does not account for octets, HTML entities, or other encoded characters.
*
* @param {string} string Title or slug to be processed
*
Expand All @@ -45,7 +45,7 @@ export function cleanForSlug( string ) {
return trim(
deburr( string )
.replace( /[\s\./]+/g, '-' )
.replace( /[^\w-]+/g, '' )
.replace( /[^\p{L}\p{N}_-]+/gu, '' )
aristath marked this conversation as resolved.
Show resolved Hide resolved
.toLowerCase(),
'-'
);
Expand Down