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 #331 - Invalid characters in component name #332

Merged
merged 2 commits into from Aug 6, 2019

Conversation

christopher-gibson
Copy link
Contributor

Summary

fixes #331 - Filenames may contain invalid characters for javascript variable names, so they need to be removed.

Test plan

Add a few tests to check that the characters are removed.

@neoziro There a few ways to handle this, but I'm not sure which way is preferred.

  1. Remove a few known characters that might cause issues (~!@#%&?)
  2. Have a whitelist of characters (a-zA-Z0-9_-)

With option 1 we may run into more characters later that need to be added. Option 2 might have the issue of a filename with only invalid characters, or characters that are actually valid but are removed anyways (unicode).

@vercel
Copy link

vercel bot commented Aug 6, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Copy link
Owner

@gregberge gregberge left a comment

Choose a reason for hiding this comment

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

Your method is the good one, thanks for your contribution!

pascalCase: true,
})
const pascalCaseFileName = camelcase(
path.parse(state.filePath).name.replace(/[^a-zA-Z0-9_-]/g, ''),
Copy link
Owner

Choose a reason for hiding this comment

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

Can you please extract the RegExp in a constant outside the function (it is faster).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@codecov
Copy link

codecov bot commented Aug 6, 2019

Codecov Report

Merging #332 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #332      +/-   ##
==========================================
+ Coverage      85%   85.03%   +0.03%     
==========================================
  Files          30       30              
  Lines         480      481       +1     
  Branches      134      134              
==========================================
+ Hits          408      409       +1     
  Misses         60       60              
  Partials       12       12
Impacted Files Coverage Δ
packages/core/src/state.js 100% <100%> (ø) ⬆️

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 28f5285...50710d1. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Aug 6, 2019

Codecov Report

Merging #332 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #332      +/-   ##
==========================================
+ Coverage      85%   85.03%   +0.03%     
==========================================
  Files          30       30              
  Lines         480      481       +1     
  Branches      134      134              
==========================================
+ Hits          408      409       +1     
  Misses         60       60              
  Partials       12       12
Impacted Files Coverage Δ
packages/core/src/state.js 100% <100%> (ø) ⬆️

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 28f5285...50710d1. Read the comment docs.

@gregberge gregberge merged commit 4b4bd2c into gregberge:master Aug 6, 2019
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.

SyntaxError when filename has invalid variable characters (&)
2 participants