Repository navigation
fix: escape quotes in printed attribute values - #19365
Merged
Rich-Harris merged 1 commit intoNov 23, 2026
Merged
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/svelte/c/bc91e0e2c872a006c43052a1b330ef4d6fdee5a9Open in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: bc91e0e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
What this fixes
print()preserves attribute value text as raw (#19292) but wraps it in double quotes without escaping a"in the raw text. A source attribute written with single quotes can legally contain"— for example<div style='font-family: "Arial"'>,<Child prop='"' />, orstyle:color='"red"'. Printing emits<div style="font-family: "Arial"">, which fails to re-parse withexpected_token. The same happens forstyle:directives, mixed Text/expression chunks, SVG and custom elements.This escapes
"as"for Text chunks inAttributeandStyleDirectivevalues only. The parser decodes the entity back to the same value; inputs without"print byte-identically, and the AST is not mutated.Tests
packages/svelte/tests/print/samples/attribute-quotes/covers a normal attribute,style:directives with modifiers, mixed chunks, a component prop, SVG and a custom element. It fails onmainand passes here.pnpm test print— 57/57.pnpm test— 46 files, 8423 passed, 39 skipped.pnpm checkandpnpm lint.mainand 0 here; only those 3 files changed.&, CRLF, expression-only values, style modifiers, SVG/custom elements, nested subnodes) re-parses with identical client/server compile output.Notes
title='say "hi"'example from closed fix: escape text and attribute values inprint#18909 still fails onmain; this PR fixes that case. fix: keep the quotes around a single expression attribute value inprint#19231 is a different quoting bug in the same visitor and may need a trivial rebase.