\./],
["query-string ampersand escaped", `https://example.com/a?x=1&y=2`, /x=1&y=2/],
["paragraphs", `one\n\ntwo`, /one<\/p>
two<\/p>/],
["line break", `one\ntwo`, /one
two/],
];
let failed = 0;
for (const [name, input] of attacks) {
const out = renderCommentHtml(input);
const problems = auditTags(out);
// Anything the user wrote with a '<' must come back escaped.
if (input.includes("<") && !out.includes("<")) {
problems.push("angle bracket was not escaped");
}
if (problems.length > 0) {
console.error(`FAIL ${name}\n ${problems.join("; ")}\n ${out}`);
failed += 1;
} else {
console.log(`ok ${name} (neutralised)`);
}
}
for (const [name, input, expect] of features) {
const out = renderCommentHtml(input);
if (expect.test(out)) {
console.log(`ok ${name}`);
} else {
console.error(`FAIL ${name} did not match ${expect}\n ${out}`);
failed += 1;
}
}
if (failed > 0) {
console.error(`\n${failed} check(s) failed`);
process.exit(1);
}
console.log("\nAll comment-render checks passed.");