fix: iteratively strip HTML tags in search index builder

Addresses CodeQL alert about incomplete multi-character sanitization.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nate 2026-03-20 14:21:08 -07:00
parent 5635f6e5c5
commit 32ac9f14c8

View file

@ -33,8 +33,14 @@ function getAllDocSlugs(nav: any[]): string[] {
}
function stripMdx(content: string): string {
return content
.replace(/<[^>]+>/g, "")
// Iteratively strip HTML tags to handle nested/malformed tags
let stripped = content;
let prev = "";
while (prev !== stripped) {
prev = stripped;
stripped = stripped.replace(/<[^>]+>/g, "");
}
return stripped
.replace(/```[\s\S]*?```/g, "")
.replace(/`[^`]+`/g, "")
.replace(/!\[.*?\]\(.*?\)/g, "")