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

Handle single quote escaping in ids #3632

Merged
merged 7 commits into from Jun 13, 2020
Merged

Handle single quote escaping in ids #3632

merged 7 commits into from Jun 13, 2020

Conversation

guybedford
Copy link
Contributor

This ensures that ids containing a single quote are properly escaped when writing in the finalizers to ensure that valid JavaScript is outputted.

For an example of a package with a quote specifier see https://www.npmjs.com/package/@chappa'ai/update-nested-dependencies.

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

@rollup-bot
Copy link
Collaborator

rollup-bot commented Jun 12, 2020

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#quoteids

or load it into the REPL:
https://rollupjs.org/repl/?circleci=11926

@codecov
Copy link

codecov bot commented Jun 12, 2020

Codecov Report

Merging #3632 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3632      +/-   ##
==========================================
- Coverage   96.54%   96.53%   -0.01%     
==========================================
  Files         182      183       +1     
  Lines        6243     6242       -1     
  Branches     1832     1830       -2     
==========================================
- Hits         6027     6026       -1     
  Misses        107      107              
  Partials      109      109              
Impacted Files Coverage Δ
src/Chunk.ts 100.00% <100.00%> (ø)
src/utils/escapeId.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd57d14...54fb204. Read the comment docs.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Good catch. Question: Instead of patching all finalisers, wouldn't it make more sense to sanitize all ids centrally? Otherwise it is easy to forget places where this is necessary (such as in umd.ts 😉) and it also adds quite a bit of noise. Non-relative external ids could be sanitized here

id = dep.renderPath;
while relative external ids and chunk ids could be sanitized here
renderedDependency.id = this.getRelativePath(depId, false);

@guybedford
Copy link
Contributor Author

Yeah that's much nicer - I've integrated it to those code paths.

I also added detection for newlines so that this escaping is now comprehensively spec compliant.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

I extended the test to make sure escaping actually works for renormalized external paths and also covers line-breaks. Unfortunately as the test uncovered, neither was true: Renormalized paths were broken because they were escaped twice, which I fixed by moving all escaping logic to the same place. And line-breaks were not escaped as you claimed because preceding \n with a \\ does not give you a \\n, which I fixed by adding a conversion table. Should be working now.

@lukastaegert lukastaegert merged commit d613137 into master Jun 13, 2020
@lukastaegert lukastaegert deleted the quoteids branch June 13, 2020 19:22
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.

None yet

3 participants