chore(share): keep diacritics in slug instead of stripping them in

This commit is contained in:
Elian Doran 2025-10-23 14:29:47 +03:00
parent 0fa1c0f5c4
commit aae90ede19
No known key found for this signature in database
2 changed files with 6 additions and 6 deletions

View File

@ -704,9 +704,10 @@ describe("#slugify", () => {
expect(result).toBe(expectedSlug);
});
it("removes diacritic marks from characters", () => {
// preserves diacritic marks
it("preserves diacritic marks", () => {
const testString = "Café naïve façade jalapeño";
const expectedSlug = "cafe-naive-facade-jalapeno";
const expectedSlug = "café-naïve-façade-jalapeño";
const result = utils.slugify(testString);
expect(result).toBe(expectedSlug);
});

View File

@ -499,11 +499,10 @@ export function formatSize(size: number | null | undefined) {
function slugify(text: string) {
return text
.normalize("NFKD") // decompose accents
.replace(/\p{Mark}/gu, "") // remove diacritics cleanly
.normalize("NFC") // keep composed form, preserves accents
.toLowerCase()
.replace(/[^\p{Letter}\p{Number}]+/gu, "-") // keep Unicode letters/numbers
.replace(/(^-|-$)+/g, ""); // trim leading/trailing dashes
.replace(/[^\p{Letter}\p{Number}]+/gu, "-") // replace non-letter/number with "-"
.replace(/(^-|-$)+/g, ""); // trim dashes
}
export default {