All files / roosterjs-content-model-dom/lib/modelApi/common stripInvisibleUnicode.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15      1x               1x 10x    
// According to https://embracethered.com/blog/posts/2024/hiding-and-finding-text-with-unicode-tags/
// there are some invisible unicode characters in the range of U+E0000 to U+EFFFF, which are used for hiding text in HTML.
// We need to strip them out before processing the pasted content, otherwise they will be treated as normal text and cause unexpected behavior.
const INVISIBLE_UNICODE_REGEX = /[\u{E0000}-\u{EFFFF}]/gu;
 
/**
 * @internal
 * Strip invisible unicode characters from the given string
 * @param value The string to be processed
 * @returns The string with invisible unicode characters removed
 */
export function stripInvisibleUnicode(value: string): string {
    return value.replace(INVISIBLE_UNICODE_REGEX, '');
}