From c972fe6cec8f643fbafd0fe33b461798faedaf80 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Wed, 7 Jul 2021 19:56:47 +0200 Subject: tests: escape lone surrogates in wptreport (#11310) --- tools/wpt/utils.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tools/wpt') diff --git a/tools/wpt/utils.ts b/tools/wpt/utils.ts index 13c68ec90..1f76ff128 100644 --- a/tools/wpt/utils.ts +++ b/tools/wpt/utils.ts @@ -154,6 +154,16 @@ export async function cargoBuild() { assert(status.success, "cargo build failed"); } +export function escapeLoneSurrogates(input: string): string; +export function escapeLoneSurrogates(input: string | null): string | null; +export function escapeLoneSurrogates(input: string | null): string | null { + if (input === null) return null; + return input.replace( + /[\uD800-\uDFFF]/gu, + (match) => `U+${match.charCodeAt(0).toString(16)}`, + ); +} + /// WPTREPORT export async function generateRunInfo(): Promise { -- cgit v1.2.3