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

Unexpected behaviors when using Regular Expressions #145

Open
o-alexandre-felipe opened this issue Dec 28, 2021 · 0 comments
Open

Unexpected behaviors when using Regular Expressions #145

o-alexandre-felipe opened this issue Dec 28, 2021 · 0 comments
Labels

Comments

@o-alexandre-felipe
Copy link

o-alexandre-felipe commented Dec 28, 2021

Environment

command output
npx nectar --version NectarJS v0.7.115
npx --version 8.1.2
node --version v16.13.1

1. Escaping quotes in regular expressions.

echo '/"/g' > main.js;
npx nectar main.js

gives

SyntaxError: unknown: Unterminated string constant. (1:6) - make sure this is an expression.
> 1 | ("/"/g")

This works if instead of /"/ we use /\x22/

2. Replacing inline regular expression does not work

cat > main.js <<EOF
var x = '"text"';
console.log(x.replace(/\\x22/g, "\\""))
EOF
npx nectar main.js;
./main.js

gives

"text"

Notice that the expected output is \"text\", the same happens if we try to replace the e for something else.

The same is true for new RegExp("\x22", "g")

3 Literal regular expressions produce string

console.log(typeof /e/) //  gives string
console.log(typeof new RegExp('e')) // gives object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants