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: unescape backslashes on the way into the parser #52

Merged
merged 1 commit into from
Dec 12, 2023
Merged

Conversation

43081j
Copy link
Owner

@43081j 43081j commented Dec 10, 2023

We already account for escape sequences added to the AST later on (i.e. something like stylelint, postcss, etc has mutated it).

However, we do not unescape sequences on the way into the parser.

For example:

css`
  .foo {
    content: "\\abc";
  }
`;

This is already escaped, once for JS, once for the resulting CSS.

When we parse this, we extract the CSS and keep the double-escape. This of course means the resulting CSS file internally has one too many escapes.

Fixes #51
To account for this, we now unescape CSS on the way in (i.e. replace double escapes with single).

We already account for escape sequences added to the AST _later on_
(i.e. something like stylelint, postcss, etc has mutated it).

However, we do not unescape sequences on the way into the parser.

For example:

```ts
css`
  .foo {
    content: "\\abc";
  }
`;
```

This is already escaped, once for JS, once for the resulting CSS.

When we parse this, we extract the CSS _and keep the double-escape_.
This of course means the resulting CSS file internally has one too many
escapes.

To account for this, we now unescape CSS on the way in (i.e. replace
double escapes with single).
Copy link

github-actions bot commented Dec 10, 2023

Pull Request Test Coverage Report for Build 7159393284

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 96.71%

Totals Coverage Status
Change from base Build 4308425324: 0.01%
Covered Lines: 901
Relevant Lines: 909

💛 - Coveralls

Copy link
Contributor

@adrianbruntonsagecom adrianbruntonsagecom left a comment

Choose a reason for hiding this comment

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

Seems to solve it, thanks!

@43081j 43081j merged commit 59beb40 into master Dec 12, 2023
@43081j 43081j deleted the backslashery branch December 12, 2023 17:56
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.

Slashes incorrectly escaped in output?
2 participants