You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
webfetch skips HTML conversion for mixed-case media types #49322
webfetch skips HTML conversion when the server uses different casing in its media type.
For example, a response with:
Content-Type: Text/HTML; Charset=UTF-8
passes the textual-content check, but format: "markdown" and format: "text" return the raw HTML. The conversion path checks the original header with a case-sensitive includes("text/html").
HTTP media types are case-insensitive. Mixed-case text/html values should behave like lowercase text/html.
Plugins
Built-in webfetch only.
OpenCode version
V2 source at ba753b383f678896eb8df8f243faecc9f4e27c66.
Steps to reproduce
Return <h1>Hello</h1> with Content-Type: Text/HTML; Charset=UTF-8.
Thanks for the clear report. I've reproduced this on the latest dev (950111ff).
I used the existing webfetch tool tests with a faked response that returns <h1>Hello</h1>:
With Content-Type: text/html; charset=utf-8, format: "markdown" returns # Hello and format: "text" returns Hello.
With Content-Type: Text/HTML; Charset=UTF-8, both formats return the raw <h1>Hello</h1>.
It happens as you describe. The textual-content check uses the lowercased media type, but convert() in packages/core/src/tool/plugin/webfetch.ts checks the original header with a case-sensitive includes("text/html"). The script below reproduces it against a source checkout.
Reproduction script (repro.sh)
#!/usr/bin/env bash# Reproduces #49322: webfetch skips HTML conversion for mixed-case Content-Type.# Usage: REPO=/path/to/opencode/checkout bash repro.sh (after `bun install` in the repo)set -euo pipefail
REPO="${REPO:-/workspace/repo}"
T="$REPO/packages/core/test/tool-webfetch-mixedcase.repro.test.ts"# Reuse the existing webfetch test harness (mock HTTP layer) and add one case.
head -n "$(grep -n '^describe("WebFetchTool helpers"'"$REPO/packages/core/test/tool-webfetch.test.ts"| cut -d: -f1)" \
"$REPO/packages/core/test/tool-webfetch.test.ts"| sed '$d'>"$T"
cat >>"$T"<<'EOF'describe("repro #49322", () => { for (const ct of ["text/html; charset=utf-8", "Text/HTML; Charset=UTF-8"]) { it.effect(`converts HTML with Content-Type: ${ct}`, () => Effect.gen(function* () { reset() respond = () => Effect.succeed(new Response("<h1>Hello</h1>", { headers: { "content-type": ct } })) const registry = yield* Tool.Service const md: any = yield* executeTool(registry, call({ url: "https://1.1.1.1", format: "markdown" })) const txt: any = yield* executeTool(registry, call({ url: "https://1.1.1.1", format: "text" })) console.log(`[${ct}] markdown=${JSON.stringify(md.content?.[0]?.text)} text=${JSON.stringify(txt.content?.[0]?.text)}`) expect(md.content?.[0]?.text).toBe("# Hello") expect(txt.content?.[0]?.text).toBe("Hello") }), ) }})EOFcd"$REPO/packages/core"
bun test"$T"|| status=$?
rm -f "$T"exit"${status:-0}"
Same root cause as #63888, fixed together in #66871.
convert() compared the header with a case-sensitive includes("text/html"), so Text/HTML; Charset=UTF-8 fell through while the textual-content check above it had already accepted the response. It now matches through mimeFrom, which lowercases the type and drops the charset parameter.
The PR carries your repro as its own test: <h1>Hello</h1> served with Text/HTML; Charset=UTF-8 returns # Hello for markdown and Hello for text; on dev both come back as the raw markup.
Activity
opencodejr commentedon Oct 28, 2026
Thanks for the clear report. I've reproduced this on the latest
dev(950111ff).I used the existing webfetch tool tests with a faked response that returns
<h1>Hello</h1>:Content-Type: text/html; charset=utf-8,format: "markdown"returns# Helloandformat: "text"returnsHello.Content-Type: Text/HTML; Charset=UTF-8, both formats return the raw<h1>Hello</h1>.It happens as you describe. The textual-content check uses the lowercased media type, but
convert()inpackages/core/src/tool/plugin/webfetch.tschecks the original header with a case-sensitiveincludes("text/html"). The script below reproduces it against a source checkout.Reproduction script (repro.sh)
Run it:
bash repro.shfix(core): convert XHTML and mixed-case HTML in webfetch
Guembri01 commentedon Nov 27, 2026
Same root cause as #63888, fixed together in #66871.
convert()compared the header with a case-sensitiveincludes("text/html"), soText/HTML; Charset=UTF-8fell through while the textual-content check above it had already accepted the response. It now matches throughmimeFrom, which lowercases the type and drops thecharsetparameter.The PR carries your repro as its own test:
<h1>Hello</h1>served withText/HTML; Charset=UTF-8returns# HelloformarkdownandHellofortext; ondevboth come back as the raw markup.fix(core): convert XHTML and mixed-case HTML in webfetch
fix(core): convert XHTML and mixed-case HTML in webfetch