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

fix: handle module IDs containing quotes #683

Merged
merged 2 commits into from
Jan 3, 2023

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Dec 27, 2022

Changes

  • Escape single quotes in module identifiers

Testing

  • Added a test to the printer's tests

Docs

  • no docs updated

its possible you can have a file named foo'bar.astro which currently will trip up the compiler, since it'd produce something along the lines of createComponent(..., 'foo'bar') (ofc syntactically incorrect).

let me know if this is the wrong way to fix it and i'll update

i also added an editorconfig, let me know if its wrong. it'd be useful to have one in this repo so contributors automatically use the right indentation etc

@changeset-bot
Copy link

changeset-bot bot commented Dec 27, 2022

🦋 Changeset detected

Latest commit: 468b57a

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

This PR includes changesets to release 1 package
Name Type
@astrojs/compiler 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

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

I don't have an opinion on the .editorconfig addition, but putting an approval for the code changes.

Comment on lines +2494 to +2495
escapedModuleId := strings.ReplaceAll(tt.moduleId, "'", "\\'")
toMatch += suffixWithModuleId(escapedModuleId)
Copy link
Member

Choose a reason for hiding this comment

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

I think for complete correctness we might want to use:

func escapeForJSON(value string) string {

but since this is a file path, it would almost always not have double backslashes to mess up the replacements, so I think this is fine for now.

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.

This change looks good to me!

@natemoo-re natemoo-re merged commit 47de01a into withastro:main Jan 3, 2023
@43081j 43081j deleted the quoted-module-ids branch January 3, 2023 18:49
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.

3 participants