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

# inside quotes still treated as inline comment #631

Closed
rmclaughlin-nelnet opened this issue Feb 21, 2022 · 2 comments
Closed

# inside quotes still treated as inline comment #631

rmclaughlin-nelnet opened this issue Feb 21, 2022 · 2 comments

Comments

@rmclaughlin-nelnet
Copy link

This is very similar to #601 because I am still seeing this issue in v16

I have a .env file that looks like this

KEY1="~`! @#$%^&*()_-+={[}]|\:;"'<,>.?/"
KEY2='~`! @#$%^&*()_-+={[}]|\:;"'<,>.?/'
KEY3=`~`! @#$%^&*()_-+={[}]|\:;"'<,>.?/`

When I run this code

const dotenv = require('dotenv');
console.log(JSON.stringify(dotenv.config()));

the output I get is

{"parsed":{"KEY1":"\"~`! @","KEY2":"'~`! @","KEY3":"`~`! @"}}
@jeffslofish
Copy link
Contributor

Each of the three strings has the string delimiter for that line somewhere in the middle of the string. For example, the " character is nine characters from the end of the first line. If you remove the " character from that line (and the extra ' from the second line and the extra ` from the third line), then the output will be as expected.

It is odd that these extra characters are causing it to treat everything after # as a comment.

Also, it doesn't seem like there is a way to have an environment variable with all three string delimiters in it.

@motdotla
Copy link
Owner

motdotla commented Feb 5, 2024

thanks @jeffslofish. yes, @rmclaughlin-nelnet the additional ", ', and ` must be escaped.

here's a working example: https://github.com/dotenv-org/examples/blob/master/usage/dotenv-nodejs-inline-comments/.env

KEY1="~`! @#$%^&*()_-+={[}]|\:;\"'<,>.?/"
KEY2='~`! @#$%^&*()_-+={[}]|\:;"\'<,>.?/'
KEY3=`~\`! @#$%^&*()_-+={[}]|\:;"'<,>.?/`
Screenshot 2024-02-05 at 3 41 18 PM

@motdotla motdotla closed this as completed Feb 5, 2024
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

3 participants