godotenv icon indicating copy to clipboard operation
godotenv copied to clipboard

Behaviour deviates from Node dotenv

Open harishnair96 opened this issue 9 months ago • 1 comments

I am using the following code to compare the difference in behaviour.

require('dotenv').config()

console.log(process.env.TEST_ENV)
package main

import (
	"fmt"
	"os"

	"github.com/joho/godotenv"
)

func main() {
	if err := godotenv.Load(); err != nil {
		fmt.Fprintln(os.Stderr, err)
	}
	fmt.Println(os.Getenv("TEST_ENV"))
}
  1. Double quotes without escape

    TEST_ENV="test"test"
    

    Node dotenv worked but godotenv failed to even parse the env file.

    Image
  2. Double quotes with escape

    TEST_ENV="test\"test"    
    

    Node dotenv parsed the value literally but gotdotenv used \ to escape the double quote.

    Image
  3. Exclamation mark with escape

    TEST_ENV="test\!test"
    

    Node dotenv parsed the value literally but godotenv used \ to escape the exclamation mark.

    Image

    An additional point here is that both the libraries parses exclamation marks without escape as well.

    TEST_ENV="test!test"
    
    Image

    However godotenv escapes exclamation during marshalling.

harishnair96 avatar Feb 26 '25 08:02 harishnair96

HI @joho can I address this? If this needs to be done then I can try working on this.

ayushdoesdev avatar Nov 12 '25 10:11 ayushdoesdev