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

'$' in code duplicates code with certain matchers #208

Closed
lucaswerkmeister opened this issue Oct 9, 2016 · 1 comment
Closed

'$' in code duplicates code with certain matchers #208

lucaswerkmeister opened this issue Oct 9, 2016 · 1 comment

Comments

@lucaswerkmeister
Copy link
Contributor

Minimal example:

#!/usr/bin/node
const rainbow = require('rainbow-code');
rainbow.extend("bug", [{pattern: /'[^']*'/gm}], true);
if (rainbow.colorSync("'$'x", "bug").match(/x/g).length > 1)
    console.error("DUPLICATED");

This example adds a very simple rule for character literals: single quote, not single quotes, single quote. When it is applied to the code '$'x, the x appears in the output twice.

We discovered this in our Ceylon language (eclipse-archived/ceylon#6559); however, the Java language shipped with Rainbow suffers from the same problem:

const rainbow = require('rainbow-code')
rainbow.colorSync("'$'foobarbazfoobarbaz", "java")
// '<span class="char">\'foobarbazfoobarbaz</span>foobarbazfoobarbaz'

And in Python, the code following the dollar sign isn’t duplicated, but the dollar sign and one single quote still vanish:

rainbow.colorSync("('$')", "python")
// '(<span class="string">\'</span>)'
@lucaswerkmeister
Copy link
Contributor Author

I have found a fix for this issue and will push it shortly.

lucaswerkmeister added a commit to lucaswerkmeister/rainbow that referenced this issue Oct 9, 2016
Any occurrence of $ in the replacement string must be replaced with $$
to ensure that it's not interpreted as a special replacement pattern.
lucaswerkmeister added a commit to lucaswerkmeister/rainbow that referenced this issue Oct 9, 2016
lucaswerkmeister added a commit to lucaswerkmeister/rainbow that referenced this issue Jul 26, 2017
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

No branches or pull requests

1 participant