BUG parsing escape of double quote - adding more slash
Author: sunshine69Created Aug 5, 2026Updated Aug 5, 2026
Hi I got a test program
package main
import (
"fmt"
"os"
"github.com/joho/godotenv"
)
func main() {
// Simpler case Dump it to file
if err := godotenv.Write(map[string]string{
"PASSWORD": `abvd"`,
}, ".env1"); err != nil {
panic(err.Error())
}
// Read it back
envMap, err := godotenv.Read(".env1")
if err != nil {
panic(err)
}
if c, err := os.ReadFile(".env1"); err == nil {
fmt.Println("=== .env content ===")
fmt.Println(string(c))
} else {
panic(err.Error())
}
fmt.Println()
fmt.Println("=== godotenv.Read() ===")
fmt.Printf("%s\n", envMap["PASSWORD"])
}
If u run it it prints
go run .
=== .env content ===
PASSWORD="abvd\""
=== godotenv.Read() ===
abvd\See the extra \ when read? this is wrong
It should print remove backspace on the back tick and on the quote but keep the quote. Like abvd" - that is the password has " in it.
It dump to a file, using correct data - then it would be able to read it back intact.
Source: joho/godotenv