Skip to content

Commit

Permalink
Merge pull request #3036 from cloudflare/npaun/wpt-bom
Browse files Browse the repository at this point in the history
WPT: Replace invalid characters in test names
  • Loading branch information
npaun authored Oct 31, 2024
2 parents fbd611c + c60595d commit 7e3e636
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/wpt/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,32 @@ function prepare(options) {
globalThis.testOptions = options;
}

function sanitizeMessage(message) {
// Test logs will be exported to XML, so we must escape any characters that
// are forbidden in an XML CDATA section, namely "[...] the surrogate blocks,
// FFFE, and FFFF".
// See https://www.w3.org/TR/REC-xml/#NT-Char
return message.replace(
/[\u{D800}-\u{DFFF}\u{FFFE}\u{FFFF}]/gu,
(char) => '\\u' + char.charCodeAt().toString(16).padStart(4, '0')
);
}

async function validate(options) {
await Promise.all(globalThis.promises);

const expectedFailures = options.expectedFailures ?? [];
let failed = false;

for (const err of globalThis.errors) {
const sanitizedError = new AggregateError(
err.errors,
sanitizeMessage(err.message)
);
if (expectedFailures.includes(err.message)) {
console.warn('Expected failure: ', err);
console.warn('Expected failure: ', sanitizedError);
} else {
console.error(err);
console.error(sanitizedError);
failed = true;
}
}
Expand Down

0 comments on commit 7e3e636

Please sign in to comment.