Skip to content

fix: escape quotes in printed attribute values - #19365

Merged
Rich-Harris merged 1 commit into
sveltejs:mainfrom
BlueX888:contrib/print-attribute-quotes
Nov 23, 2026
Merged

Rich-Harris merged 1 commit into
sveltejs:mainfrom
BlueX888:contrib/print-attribute-quotes

Conversation

@BlueX888

Copy link
Copy Markdown
Contributor

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='"' />, or style:color='"red"'. Printing emits <div style="font-family: "Arial"">, which fails to re-parse with expected_token. The same happens for style: directives, mixed Text/expression chunks, SVG and custom elements.

This escapes " as &quot; for Text chunks in Attribute and StyleDirective values only. The parser decodes the entity back to the same value; inputs without " print byte-identically, and the AST is not mutated.

Tests

  • New print sample 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 on main and passes here.
  • pnpm test print — 57/57.
  • pnpm test — 46 files, 8423 passed, 39 skipped.
  • pnpm check and pnpm lint.
  • An independent 5,140-file parse → print → parse sweep had 3 invalid outputs on main and 0 here; only those 3 files changed.
  • A 36-case probe (entities, bare &, CRLF, expression-only values, style modifiers, SVG/custom elements, nested subnodes) re-parses with identical client/server compile output.

Notes

@pkg-svelte-dev

Copy link
Copy Markdown

Install the latest version of svelte from bc91e0e:

pnpm add https://pkg.svelte.dev/svelte/c/bc91e0e2c872a006c43052a1b330ef4d6fdee5a9

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/svelte/pr/19365

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Nov 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bc91e0e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@Rich-Harris
Rich-Harris merged commit cc10eb9 into sveltejs:main Nov 23, 2026
11 of 13 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants