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

saner escaping/unescaping of @ and # sigils #750

Merged
merged 4 commits into from
Aug 5, 2017
Merged

Conversation

Conduitry
Copy link
Member

@Conduitry Conduitry commented Aug 5, 2017

I say [WIP] but this should be pretty much done.

This changes the escaping of @ and # sigils to not use a prepended \ (which gets further escaped by JSON.stringify, and complicates the unescaping) and instead just increases by 1 any runs of @ or runs of #.

There are still a couple of gotchas:

  • at the point where we're escaping injected CSS, we only want to escape @, because there is no further # unescaping that happens on that string after that point. There's probably a more elegant solution than what I have. Maybe still use stringify but then immediately unescape the # ones?
  • the hash that maps characters to their HTML escaped versions in the SSR generated code contains ' as the replacement for ', which we have to now represent as &##39;. Not really a huge deal - kind of amusing more than anything.

This PR does fix the second issue I was seeing, where @s were being dropped from strings passed as attributes to nested components when compiled in SSR mode.

All existing tests pass, but some more tests should be written.

@Conduitry Conduitry changed the title [WIP] saner escaping/unescaping of @ and # sigils saner escaping/unescaping of @ and # sigils Aug 5, 2017
@Conduitry
Copy link
Member Author

Put in what's hopefully a less ugly solution for the proper CSS escaping. Also realized that same alternate escaping should be used on sharedPath, because that's only going to have @s unescaped afterwards. Added a test for what I was seeing fail before. And removed the [WIP]!

@Conduitry
Copy link
Member Author

One more fix, actually. We don't want to escape @ or # in sharedPath at all, because that doesn't run through even the @-unescaping afterwards. This is an issue on master, currently (shared: 'very@contrived#path' results in import { ... } from "very\\@contrived\\#path";) - but I don't see how to test this. Even the tests in test/js/samples have hardcoded compiler options of { shared: true }.

@Rich-Harris Rich-Harris merged commit 4874dc1 into master Aug 5, 2017
@Rich-Harris Rich-Harris deleted the saner-sigils branch August 5, 2017 13:49
@Rich-Harris
Copy link
Member

Thanks so much for taking this on! I have a curious blind spot for this stuff, as you've no doubt noticed 🙈

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