Skip to content

escape backslashes in JS string literal output#1164

Open
digi-scrypt wants to merge 1 commit into
withastro:mainfrom
digi-scrypt:escape-backslash-in-js-strings
Open

escape backslashes in JS string literal output#1164
digi-scrypt wants to merge 1 commit into
withastro:mainfrom
digi-scrypt:escape-backslash-in-js-strings

Conversation

@digi-scrypt

Copy link
Copy Markdown
  1. escapeDoubleQuote and escapeSingleQuote escape the closing quote but not the backslash, so a value ending in a backslash (or one before a quote) lands a \ right against the closing quote the printer adds and breaks out of the JS string literal.
  2. these feed the renderComponent props object, slot names and the hoisted script src metadata, all built from attribute values in the source.

A quoted attribute is the trigger. <Component path='C:\dir\' /> currently emits {"path":"C:\dir\"} which node refuses to parse; a crafted trailing backslash terminates the string early and the following bytes are no longer inside it. Same story for src on a hoisted <script>.

Escaped the backslash first in both helpers. The one place escapeNewlines wraps the value I flipped the order so the \n it inserts isn't doubled. Added a snapshot covering a backslash attribute.

@changeset-bot

changeset-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fda3d64

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

1 participant