feat(text/unstable): handle non-Latin-script text in slugify
#6012
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #5830 (2nd attempt, supersedes abandoned #5880).
transliterate
option is provided as a hook for transliteration libraries such asnpm:any-ascii
, without requiring the transliteration library to re-implement word segmenting (which is already handled byslugify
).The empty case is changed from
""
to"-"
to mitigate against unsafe slugs (URL path/a//b
normalizes to/a/b
, and often/a/
is also normalized to/a
, i.e. an empty slug allows a limited form of path traversal up one level). Maybe that's not necessary as slugs are often combined with some kind of ID, open to arguments either way on that one.Four strip regexes,
ASCII_DIACRITICS, DIACRITICS, NON_ASCII, NON_WORD
, are exported, and supplying a custom regex is also supported. PossiblyASCII_DIACRITICS
isn't really necessary? It enables a mode in which certain languages (e.g. Spanish) can still have fully ASCII slugs, yet retains diacritics in other contexts (where stripping them is strictly worse, as the slug wouldn't be ASCII even if they were removed).