Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPT: Replace invalid characters in test names #3036

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading