Skip to content

Commit 0fa1c0f

Browse files
committed
chore(share): improve slugification to strip diacritics cleanly
1 parent d2b6014 commit 0fa1c0f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

apps/server/src/services/utils.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,3 +681,33 @@ describe("#normalizeCustomHandlerPattern", () => {
681681
});
682682
});
683683
});
684+
685+
describe("#slugify", () => {
686+
it("should return a slugified string", () => {
687+
const testString = "This is a Test String! With unicode & Special #Chars.";
688+
const expectedSlug = "this-is-a-test-string-with-unicode-special-chars";
689+
const result = utils.slugify(testString);
690+
expect(result).toBe(expectedSlug);
691+
});
692+
693+
it("supports CJK characters without alteration", () => {
694+
const testString = "测试中文字符";
695+
const expectedSlug = "测试中文字符";
696+
const result = utils.slugify(testString);
697+
expect(result).toBe(expectedSlug);
698+
});
699+
700+
it("supports Cyrillic characters without alteration", () => {
701+
const testString = "Тестирование кириллических символов";
702+
const expectedSlug = "тестирование-кириллических-символов";
703+
const result = utils.slugify(testString);
704+
expect(result).toBe(expectedSlug);
705+
});
706+
707+
it("removes diacritic marks from characters", () => {
708+
const testString = "Café naïve façade jalapeño";
709+
const expectedSlug = "cafe-naive-facade-jalapeno";
710+
const result = utils.slugify(testString);
711+
expect(result).toBe(expectedSlug);
712+
});
713+
});

apps/server/src/services/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ export function formatSize(size: number | null | undefined) {
499499

500500
function slugify(text: string) {
501501
return text
502-
.normalize("NFKD") // handles accents like é → e
502+
.normalize("NFKD") // decompose accents
503+
.replace(/\p{Mark}/gu, "") // remove diacritics cleanly
503504
.toLowerCase()
504505
.replace(/[^\p{Letter}\p{Number}]+/gu, "-") // keep Unicode letters/numbers
505506
.replace(/(^-|-$)+/g, ""); // trim leading/trailing dashes

0 commit comments

Comments
 (0)