| @@ -18,10 +18,15 @@ | ||
| 18 | 18 | .toLowerCase() |
| 19 | 19 | .trim() |
| 20 | 20 | // Replace spaces and underscores with hyphens |
| 21 | 21 | .replace(/[\s_]+/g, "-") |
| 22 | - // Remove all non-word characters except hyphens | |
| 23 | - .replace(/[^\w-]+/g, "") | |
| 22 | + // Remove all non-word characters except hyphens. The Unicode property | |
| 23 | + // escapes (\p{L} = any letter, \p{N} = any digit) with the `u` flag let | |
| 24 | + // non-Latin alphabets through — Cyrillic ("Путешествие"), CJK, Devanagari, | |
| 25 | + // Arabic, etc. The previous `\w` shortcut was ASCII-only and stripped | |
| 26 | + // every Russian letter, producing an empty slug. WordPress's own | |
| 27 | + // sanitize_title() preserves these scripts server-side, so this matches. | |
| 28 | + .replace(/[^\p{L}\p{N}-]+/gu, "") | |
| 24 | 29 | // Replace multiple consecutive hyphens with a single hyphen |
| 25 | 30 | .replace(/-+/g, "-") |
| 26 | 31 | // Remove leading and trailing hyphens |
| 27 | 32 | .replace(/^-+|-+$/g, "") |