Skip to content

Commit 7ecd7d9

Browse files
heiskrCopilot
andauthored
Article API: strip HTML spans from secret scanning patterns (#60077)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b27ca3f commit 7ecd7d9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/article-api/tests/secret-scanning-transformer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ describe('secret scanning article body api', () => {
2020
// Verify HTML comments are stripped
2121
expect(res.body).not.toMatch(/<!--.*?-->/)
2222

23+
// Verify HTML icon spans are not present (would be replaced with ✓/✗)
24+
expect(res.body).not.toMatch(/<span[^>]*aria-label="Supported"/)
25+
expect(res.body).not.toMatch(/<span[^>]*aria-label="Unsupported"/)
26+
// Verify no raw HTML span tags remain
27+
expect(res.body).not.toMatch(/<span[^>]*>/)
28+
2329
// Verify table content is present with providers
2430
expect(res.body).toMatch(/|\s*Provider\s*|/)
2531
expect(res.body).toMatch(/\| (Adafruit|AWS|Alibaba|Amazon)/)

src/article-api/transformers/secret-scanning-transformer.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ export class SecretScanningTransformer implements PageTransformer {
6969
// Strip HTML comments from the rendered content
7070
content = content.replace(/<!--.*?-->/gs, '')
7171

72+
// Replace HTML icon spans with plain text equivalents
73+
content = content.replace(/<span[^>]*aria-label="Supported"[^>]*>[^<]*<\/span>/g, '✓')
74+
content = content.replace(/<span[^>]*aria-label="Unsupported"[^>]*>[^<]*<\/span>/g, '✗')
75+
// Convert <br/> tags to newlines and <a href="...">text</a> to markdown links
76+
content = content.replace(/<br\s*\/?>/gi, '\n')
77+
content = content.replace(/<a\s+href="([^"]*)"[^>]*>([^<]*)<\/a>/gi, '[$2]($1)')
78+
// Strip any remaining HTML tags (loop to handle nested/malformed tags)
79+
let previous = ''
80+
while (content !== previous) {
81+
previous = content
82+
content = content.replace(/<[^>]+>/g, '')
83+
}
84+
7285
// Normalize whitespace after stripping comments
7386
content = content.replace(/\n{3,}/g, '\n\n').trim()
7487

0 commit comments

Comments
 (0)