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

cli: escape chalk parentheses #612

Merged
merged 2 commits into from
Aug 28, 2018
Merged

cli: escape chalk parentheses #612

merged 2 commits into from
Aug 28, 2018

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Jul 31, 2018

So this seems to fix #595.


The underlying issue here is that command-line-usage uses chalk 2.x (we use chalk 1.x) which makes heavy use of template literals and introduces a curly-bracket syntax like so:

{bold some bold text} some normal text

When we pass our help text to command-line-usage, it isn't escaped (because they forcefully pass it to chalk as "raw" text which chalk doesn't escape). So our parentheses are interpreted as chalk's syntax.

Internally, chalk escapes parentheses with the exact regex i've added here.

I'm not sure if i like this fix... because this could easily occur in other places where we pass arbitrary text into chalk. Any ideas how we can generalise this a little more? Or if we need to?

{header: 'Lint Rules', content: rulesDocs.join('\n\n'), raw: true}
{
header: 'Lint Rules',
content: rulesDocs.join('\n\n').replace(/[{}\\]/g, '\\$&'),
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment to explain this?

@aomarks aomarks self-requested a review August 27, 2018 22:54
@aomarks
Copy link
Member

aomarks commented Aug 27, 2018

Also a CHANGELOG entry please

@43081j
Copy link
Contributor Author

43081j commented Aug 28, 2018

@aomarks thanks for taking a look at this, much appreciated.

have updated the changelog and added a small comment now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[polymer-cli] Error: Found extraneous } in Chalk template literal
3 participants