Skip to content

Commit

Permalink
WPT: Replace invalid characters in test names
Browse files Browse the repository at this point in the history
  • Loading branch information
npaun committed Oct 31, 2024
1 parent fbd611c commit c60595d
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 c60595d

Please sign in to comment.