fix: strip code blocks before HTML detection in looksLikeHtml()#42
Merged
dacharyc merged 1 commit intoagent-ecosystem:mainfrom Apr 19, 2026
Merged
Conversation
looksLikeHtml() false-positives on markdown pages that contain HTML tags inside fenced code blocks or inline code spans (e.g. `<body>` or a fenced HTML example). This causes content-negotiation and markdown-url-support checks to misclassify valid markdown responses as HTML. Strip fenced code blocks and inline code spans from the sample before running HTML pattern matching.
Member
|
Thanks for the PR, @mvvmm ! There's a case where I know this particular implementation will be an issue, so I'm going to merge this and then make a small follow-up to flip the logic. You've got this code here: const sample = stripCode(body.slice(0, 2000));There's a truncation risk when an opening code fence is inside the slice and the closing code fence is outside the slice; the regex will never be able to match that case. So I'm going to swap it to: const sample = stripCode(body).slice(0, 2000);Given the size of the average page, I'm hoping the performance tradeoff is negligible compared to the network I/O of the page fetch. If this becomes an issue in practice, I'm open to exploring other options. Thank you for the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
looksLikeHtml()false-positives on markdown pages that contain HTML tags inside fenced code blocks or inline code spans (e.g.`<body>`). This causescontent-negotiationandmarkdown-url-supportchecks to misclassify valid markdown responses as HTML.Some pages like:
include valid HTML elements in their markdown in code blocks.
Fix
Strip fenced code blocks and inline code spans from the sample before running HTML pattern matching.
Tests
Added 5 new test cases covering fenced blocks (backtick and tilde), inline code spans, and ensuring real HTML outside code is still detected.