Skip to content

Commit c3fc3b5

Browse files
Potential fix for code scanning alert no. 3: Incomplete multi-character sanitization
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent faaff6c commit c3fc3b5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

app/docs/[...slug]/page.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ import path from "path";
1717

1818
// Extract clean text content from MDX
1919
function extractTextFromMDX(content: string): string {
20-
return content
20+
let text = content
2121
.replace(/^---[\s\S]*?---/m, "") // Remove frontmatter
2222
.replace(/```[\s\S]*?```/g, "") // Remove code blocks
23-
.replace(/`([^`]+)`/g, "$1") // Remove inline code
24-
.replace(/<[^>]+>/g, "") // Remove HTML/MDX tags
23+
.replace(/`([^`]+)`/g, "$1"); // Remove inline code
24+
// Remove HTML/MDX tags recursively to prevent incomplete multi-character sanitization
25+
let prevText;
26+
do {
27+
prevText = text;
28+
text = text.replace(/<[^>]+>/g, "");
29+
} while (text !== prevText);
30+
return text
2531
.replace(/\*\*([^*]+)\*\*/g, "$1") // Remove bold
2632
.replace(/\*([^*]+)\*/g, "$1") // Remove italic
2733
.replace(/#{1,6}\s+/g, "") // Remove headers

0 commit comments

Comments
 (0)