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
Markdown image alt and title attributes double-escape ampersands #18070
- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)triage: fix pendingReporter needs to verify the triage bot fix works
Astro v7.2.9
Vite v8.2.2
Node v24.19.0
System Linux (x64)
Package Manager npm
Output static
Adapter none
Integrations none
If this issue only occurs in one browser, which browser is a problem?
Not browser-specific; present in generated HTML.
Describe the Bug
With Satteri (satteri: 0.10.5 & @astrojs/markdown-satteri: 0.3.8) and a local image, an ampersand in Markdown image alt or title text is escaped twice. This changes the browser's attribute value.
Input:

Output (other attributes omitted):
<imgalt="A &amp; B" title="C &amp; D">
The DOM attribute values are "A & B" and "C & D".
Reproduced on Astro 7.2.9 in both:
A glob() content collection rendered with getEntry(), render(), and <Content />.
An ordinary Markdown page under src/pages/.
Steps for the reproduction:
Run npm install.
Run npm run build (astro build --force).
Inspect dist/index.html and dist/direct/index.html. Both contain the double-escaped attributes.
The reproduction uses the Satteri processor and a small local SVG, without custom plugins or dependency patches. The build exits 0.
What's the expected result?
The DOM alt should be "A & B" and title should be "C & D". Generated HTML may use & or an equivalent single character reference. Literal entity text must be preserved, and final HTML attribute escaping must remain enabled.
Unit Test: Yes — packages/astro/test/units/vite-plugin-markdown/images.test.ts (7 test cases)
Priority:P4: important. This affects any Markdown image whose alt or title contains an & — a common character. It corrupts the rendered HTML output with the default Satteri processor, producing visibly wrong text in the browser (e.g. "A & B" instead of "A & B").
When Satteri serializes the __ASTRO_IMAGE_ marker attribute to HTML, it encodes & as &, " as ", and ' as '. The image decode logic in runtime.ts and vite-plugin-markdown/images.ts reverses "/" and '/' before JSON.parse, but does not decode &/&. The un-decoded & becomes literal text in the parsed alt/title strings, and when the final <img> tag is rendered, the & in & gets re-escaped to &amp;.
I found a potential fix for this issue. The fix adds .replace(/&(?:#x26|amp);/g, '&') to the end of each decode chain in all 4 affected locations. The & decode is placed last to prevent double-decoding (e.g. &quot; correctly becomes the literal text ", not a quotation mark).
Try this fix
You can test this fix right now without waiting for a release:
# astro
npm i https://pkg.pr.new/astro@d6f2607
If this fixes your issue, please leave a comment letting us know (for example
"confirmed, this fixes it"). A pull request will then be opened to get it merged.
Full Triage Report
Reproduction
Created a minimal project with:
A Markdown page at src/pages/direct/index.md containing 
A content collection post with the same image syntax, rendered via getEntry() / render() / <Content />
Both paths produced alt="A &amp; B" title="C &amp; D" in the generated HTML.
Root Cause
The __ASTRO_IMAGE_ attribute contains JSON-encoded image properties. Satteri's HTML serializer encodes the attribute value, turning & → &, " → ", ' → '. The decode logic reverses quotes and apostrophes but not ampersands:
// Before (incomplete — missing & decode)JSON.parse(imagePath.replace(/&(?:#x22|quot);/g,'"').replace(/&(?:#x27|apos);/g,"'"))
After JSON.parse, the alt/title values contain literal & text, which gets re-escaped to &amp; during final HTML rendering.
Affected Files
packages/astro/src/content/runtime.ts line 482 (content collections path)
Added .replace(/&(?:#x26|amp);/g, '&') to the end of each decode chain. The ordering is critical — & must be decoded last so that &quot; becomes the literal text " rather than a double-decoded quotation mark.
Verification
Before fix:alt="A &amp; B" / title="C &amp; D" (double-escaped)
After fix:alt="A & B" / title="C & D" (correct)
All existing tests pass (image-references, markdown-rendering, asset-imports, 188 asset tests).
Literal entity text preservation (&quot; → ", not ")
Quotes, apostrophes, plain text, and multiple ampersands
Changeset
.changeset/cool-paws-trade.md — astro: patch
This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.
- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)triage: fix pendingReporter needs to verify the triage bot fix works
Activity
astro-factory commentedon Sep 18, 2026
Triage complete
triage: fix pendingmain).packages/astro/test/units/vite-plugin-markdown/images.test.ts(7 test cases)altortitlecontains an&— a common character. It corrupts the rendered HTML output with the default Satteri processor, producing visibly wrong text in the browser (e.g. "A & B" instead of "A & B").When Satteri serializes the
__ASTRO_IMAGE_marker attribute to HTML, it encodes&as&,"as", and'as'. The image decode logic inruntime.tsandvite-plugin-markdown/images.tsreverses"/"and'/'beforeJSON.parse, but does not decode&/&. The un-decoded&becomes literal text in the parsed alt/title strings, and when the final<img>tag is rendered, the&in&gets re-escaped to&amp;.I found a potential fix for this issue. The fix adds
.replace(/&(?:#x26|amp);/g, '&')to the end of each decode chain in all 4 affected locations. The&decode is placed last to prevent double-decoding (e.g.&quot;correctly becomes the literal text", not a quotation mark).Try this fix
You can test this fix right now without waiting for a release:
# astro npm i https://pkg.pr.new/astro@d6f2607If this fixes your issue, please leave a comment letting us know (for example
"confirmed, this fixes it"). A pull request will then be opened to get it merged.
Full Triage Report
Reproduction
Created a minimal project with:
src/pages/direct/index.mdcontaininggetEntry()/render()/<Content />Both paths produced
alt="A &amp; B" title="C &amp; D"in the generated HTML.Root Cause
The
__ASTRO_IMAGE_attribute contains JSON-encoded image properties. Satteri's HTML serializer encodes the attribute value, turning&→&,"→",'→'. The decode logic reverses quotes and apostrophes but not ampersands:After
JSON.parse, the alt/title values contain literal&text, which gets re-escaped to&amp;during final HTML rendering.Affected Files
packages/astro/src/content/runtime.tsline 482 (content collections path)packages/astro/src/vite-plugin-markdown/images.tslines 26, 45, 60 (direct Markdown page path)Fix Details
Added
.replace(/&(?:#x26|amp);/g, '&')to the end of each decode chain. The ordering is critical —&must be decoded last so that&quot;becomes the literal text"rather than a double-decoded quotation mark.Verification
alt="A &amp; B"/title="C &amp; D"(double-escaped)alt="A & B"/title="C & D"(correct)All existing tests pass (image-references, markdown-rendering, asset-imports, 188 asset tests).
Unit Tests Added
packages/astro/test/units/vite-plugin-markdown/images.test.ts— 7 tests covering:&from Satteri)&from remark)&quot;→", not")Changeset
.changeset/cool-paws-trade.md—astro: patchThis report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.
Princesseuh commentedon Sep 21, 2026
Fixed by #18086