test(ui): repair current main test baseline (#3191)

This commit is contained in:
Alan Shum
2026-08-28 15:44:40 +03:00
committed by GitHub
parent 5faa1a6531
commit 73e21d0050
3 changed files with 28 additions and 3 deletions
@@ -19,6 +19,15 @@ const sanitizeHooks: {
afterSanitizeAttributes?: (node: unknown) => void;
} = {};
// Mirrors DOMPurify's default URI policy: approved schemes plus relative URLs.
const DOMPURIFY_ALLOWED_URI_RE =
// Keep this byte-aligned with DOMPurify's default IS_ALLOWED_URI expression.
// eslint-disable-next-line no-useless-escape
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
const URI_ATTRIBUTE_WHITESPACE_RE =
// eslint-disable-next-line no-control-regex
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g;
Object.assign(globalThis, {
window: {},
HTMLAnchorElement: TestAnchorElement,
@@ -36,7 +45,10 @@ mock.module('dompurify', () => ({
sanitizeHooks.uponSanitizeAttribute?.(anchor, data);
sanitizeHooks.afterSanitizeAttributes?.(anchor);
return data.forceKeepAttr || /^(?:https?|mailto|tel):/i.test(href) ? attribute : '';
const normalizedHref = href.replace(URI_ATTRIBUTE_WHITESPACE_RE, '');
return data.forceKeepAttr || DOMPURIFY_ALLOWED_URI_RE.test(normalizedHref)
? attribute
: '';
}),
},
}));