Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaping template literals in HTML attribute value strings #439

Merged
merged 1 commit into from
Jun 22, 2022

Conversation

tony-sull
Copy link

@tony-sull tony-sull commented Jun 22, 2022

Closes #437

Changes

Backticks in plain HTML attributes needs to escaped in the render output

Current Behavior

The snippet below is an example of the compiled output when a backtick is used in an HTML attribute

return $$render`<html lang="en">
	<head>
		<!-- Load AlpineJS on the page -->

	<!--astro:head--></head>
	<body>
		<main>
			<a :href="`/home`">Home</a>
		</main>
	</body></html>`; 
        /** ... */
`

The build breaks here because the backtick in <a :href isn't escaped, splitting the template literal early

Testing

  • Added token and printer tests to verify the backticks are being escaped in attribute values
  • Tested manually by doing the escaping in Astro core in between transform() and compile()

Docs

bug fix only

@changeset-bot
Copy link

changeset-bot bot commented Jun 22, 2022

⚠️ No Changeset found

Latest commit: 83110df

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

@tony-sull tony-sull self-assigned this Jun 22, 2022
@tony-sull tony-sull changed the title fix: escape template literals in HTML attribute value strings Escaping template literals in HTML attribute value strings Jun 22, 2022
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

You're a veritable Gopher now, @tony-sull! Thanks for the fix!

@natemoo-re natemoo-re merged commit 6f43ef5 into main Jun 22, 2022
@natemoo-re natemoo-re deleted the fix/escape-template-literals branch June 22, 2022 22:23
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.

🐛 BUG: Javascript Template literals (backticks) throws an error
2 participants