fix(shared): preserve unicode slug labels

Fixes #58932.

Carries forward #58942 and #58995.

Thanks @fengqing-git, @Starhappysh, and @koen666.
This commit is contained in:
Ke He
2026-04-29 12:56:56 +08:00
committed by GitHub
parent 16fd9a9d59
commit e3bc985a6e
3 changed files with 50 additions and 4 deletions

View File

@@ -51,23 +51,27 @@ export function normalizeCsvOrLooseStringList(value: unknown): string[] {
return [];
}
function normalizeSlugInput(raw?: string | null) {
return (normalizeOptionalLowercaseString(raw) ?? "").normalize("NFC");
}
export function normalizeHyphenSlug(raw?: string | null) {
const trimmed = normalizeOptionalLowercaseString(raw) ?? "";
const trimmed = normalizeSlugInput(raw);
if (!trimmed) {
return "";
}
const dashed = trimmed.replace(/\s+/g, "-");
const cleaned = dashed.replace(/[^a-z0-9#@._+-]+/g, "-");
const cleaned = dashed.replace(/[^\p{L}\p{M}\p{N}#@._+-]+/gu, "-");
return cleaned.replace(/-{2,}/g, "-").replace(/^[-.]+|[-.]+$/g, "");
}
export function normalizeAtHashSlug(raw?: string | null) {
const trimmed = normalizeOptionalLowercaseString(raw) ?? "";
const trimmed = normalizeSlugInput(raw);
if (!trimmed) {
return "";
}
const withoutPrefix = trimmed.replace(/^[@#]+/, "");
const dashed = withoutPrefix.replace(/[\s_]+/g, "-");
const cleaned = dashed.replace(/[^a-z0-9-]+/g, "-");
const cleaned = dashed.replace(/[^\p{L}\p{M}\p{N}-]+/gu, "-");
return cleaned.replace(/-{2,}/g, "-").replace(/^-+|-+$/g, "");
}