Skip to content

Commit

Permalink
Allow non-latin characters in slugs (#32232)
Browse files Browse the repository at this point in the history
* fixes #24710

* Additional test

* typo

* fix failing tests

* update test description

* update docs
  • Loading branch information
aristath authored and youknowriad committed Jun 7, 2021
1 parent 0d158f1 commit d9508b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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, '' )
.toLowerCase(),
'-'
);
Expand Down

0 comments on commit d9508b5

Please sign in to comment.