Skip to content

Commit 03c801f

Browse files
author
DevBot
committed
fix(www): strip article heading tags to a fixed point; drop hex-like issue ref from comment (#1281)
CodeQL js/incomplete-multi-character-sanitization re-fired on the single-pass tag strip in prepareArticle (new alert on PR #1291); apply the documented fixpoint idiom, matching the html-escape.ts sanitizeHeadExtras structure. The www theme-token gate also read '(#1281)' on a line containing 'outline' as a hex color literal; reworded.
1 parent 094c1c2 commit 03c801f

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

www/app/site-ui/article-body.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ export function prepareArticle(html: string): { html: string; outline: ArticleOu
2020
const withIds = html.replace(
2121
/<h([23])([^>]*)>([\s\S]*?)<\/h\1>/gi,
2222
(_match, depth, attrs, body) => {
23-
// Strip tags, then any angle bracket the tag pattern could not match
24-
// (e.g. a `<script` fragment with no closing `>`), so the plain-text
25-
// label can never carry a partial tag into the rail outline (#1281).
26-
const label = String(body).replace(/<[^>]+>/g, '').replace(/[<>]/g, '').replace(
27-
/&[^;]+;/g,
28-
' ',
29-
).trim();
23+
// Strip tags to a fixed point, then any angle bracket the tag pattern
24+
// could not match (e.g. a `<script` fragment with no closing `>`), so
25+
// the plain-text label can never carry a partial tag into the rail
26+
// outline (issue 1281).
27+
let label = String(body);
28+
for (;;) {
29+
const stripped = label.replace(/<[^>]+>/g, '');
30+
if (stripped === label) break;
31+
label = stripped;
32+
}
33+
label = label.replace(/[<>]/g, '').replace(/&[^;]+;/g, ' ').trim();
3034
const stem = label.toLowerCase().normalize('NFKD').replace(/[^\p{L}\p{N}]+/gu, '-').replace(
3135
/(^-|-$)/g,
3236
'',

0 commit comments

Comments
 (0)