preetpalS/emacs-dotenv-mode

KEY=value&shouldntbehighlighted=something

Closed this issue · 2 comments

Repro:

  1. enter scratch buffer
  2. put in REPRO=myvalue&THIS_SHOULDNT_BE_HIGLIGHTED=thing
  3. enable dotenv-mode

Current result is:
image

Expected result:
THIS_SHOULDNT_BE_HIGHLIGHTED shouldn't be higlighted like a key, it should be highlighted like a value


This is valid in bash:

export REPRO='myvalue&THIS_SHOULDNT_BE_HIGHLIGHTED=thing'     
echo $REPRO
myvalue&THIS_SHOULDNT_BE_HIGHLIGHTED=thing 

I initially came across this because I had a variable like OAUTH_CLIENT_SECRET which had the characters &jq= which triggers the coloring issue, and the env var's value is passed to the app just fine, so I assume havning KEY=[text]&[text]=[text] in the .env file is valid

For the given example KEY=[text]&[text]=[text], the fact that the value for KEY is passed to the app as [text]&[text]=[text] is due to the implementation of the ENV parser library used. If you want to treat your .env file as being valid bash (so you can eval your .env file to set up your environment in your shell), then THIS_SHOULDNT_BE_HIGLIGHTED (from your repro steps) actually should be highlighted, see the following bash session:

ps@ps-AB350M-DS3H:~$ echo $THIS_SHOULDNT_BE_HIGLIGHTED



ps@ps-AB350M-DS3H:~$ REPRO=myvalue&THIS_SHOULDNT_BE_HIGLIGHTED=thing

[1] 37128

ps@ps-AB350M-DS3H:~$ echo $THIS_SHOULDNT_BE_HIGLIGHTED

thing

[1]+  Done                    REPRO=myvalue

ps@ps-AB350M-DS3H:~$ 

In the session, the repro line results in the value for THIS_SHOULDNT_BE_HIGLIGHTED being set (and the REPRO=myvalue portion of the command is executed in the background). Note that if you are using ZSH (the default shell on macOS) or a different shell, the behavior might be different (I tested this on Ubuntu).

Also for comparison, the highlighting of the repro line (line 4 in both buffers) in this mode matches the behavior of Emacs's shell script mode.


Screenshot 2023-11-16 175756

I don't think that the repro line should be highlighted differently by default than the shell script mode in Emacs due to the use case I mentioned earlier where you can eval your .env files to setup your environment. If you do want the REPRO line to be highlighted differently than in shell script mode in this library, please re-open this issue (but I recommend just using quotes).

Ah I had no idea & is a valid separation sequence in bash. You are right this may be an implementation thing (JS impl dotenv on npm). Thanks for the explanation