Skip to content

Commit 4498afe

Browse files
authored
Merge pull request #47 from agent-ecosystem/fix/strip-code-follow-up
fix: address truncation risk in stripCode across slice boundaries
2 parents 1e76de0 + 25706c6 commit 4498afe

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/helpers/detect-markdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function stripCode(text: string): string {
2323
* from markdown that mentions HTML tags in code examples.
2424
*/
2525
export function looksLikeHtml(body: string): boolean {
26-
const sample = stripCode(body.slice(0, 2000));
26+
const sample = stripCode(body).slice(0, 2000);
2727
return HTML_PATTERNS.some((p) => p.test(sample));
2828
}
2929

test/unit/helpers/detect-markdown.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ describe('looksLikeHtml', () => {
4242
expect(looksLikeHtml(md)).toBe(false);
4343
});
4444

45+
it('ignores HTML in code blocks longer than 2000 characters', () => {
46+
const md =
47+
'# Setup\n\n```html\n<html>\n<body>\n' + 'x'.repeat(3000) + '\n</body>\n</html>\n```\n';
48+
expect(looksLikeHtml(md)).toBe(false);
49+
});
50+
4551
it('still detects real HTML outside of code blocks', () => {
4652
const html = '<!DOCTYPE html>\n<html>\n```not a code block\n```\n</html>';
4753
expect(looksLikeHtml(html)).toBe(true);

0 commit comments

Comments
 (0)