Skip to content

Commit c31495e

Browse files
committed
Escape tooltip text harder
Pipes will break the table, despite being delimited by both () and "". Left angle brackets don't need to be escaped in link titles, but they could present a security risk in case someone manages to break the formatting in some other way and cause them to render as an HTML element.
1 parent 2bb4cb9 commit c31495e

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎tools/misc/build-results-comment.mjs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,13 @@ function sanitizeTooltip(text) {
164164
.replace(/[\u0000-\u001F\u007F]/g, (ch) => (ch === "\n" || ch === "\r" || ch === "\t" ? " " : "�"))
165165
// prevent HTML entities in the JS output from being expanded
166166
.replace(/&/g, "&")
167-
// prevent existing backslashes from interfering with double quote escapes
167+
// HTML elements are not rendered in link titles, but escape them anyway in
168+
// case someone manages to break the Markdown in some other way
169+
.replace(/</g, "&lt;")
170+
// prevent existing backslashes from interfering with the escapes below
168171
.replace(/\\/g, "\\\\")
169-
// escape double quotes
170-
.replace(/"/g, '\\"');
172+
// escape double quotes (and pipes, which would break the table)
173+
.replace(/["|]/g, '\\$&');
171174
}
172175

173176
main();

0 commit comments

Comments
 (0)