(possible) bug in parser right-trimming escaped quotes?
Author: monerownerCreated Feb 17, 2024Updated Aug 5, 2026
The call to bytes.TrimRightFunc(src[0:i], trimFunc) in parser.go's extractVarValue removes a single escaped quote off the right side of the var value (if such a quote exists and it is the same as the quotes used to enclose the value). Is this intended behavior or a bug?
package main
import (
"fmt"
"github.com/joho/godotenv"
)
func main() {
m := map[string]string{"foo": `""`}
// Shows up in .env as foo="\"\""
godotenv.Write(m, ".env")
env, _ := godotenv.Read(".env")
// Expecting ""
// Instead prints "\
// This is because the escaping \ remains after the quote's removed
fmt.Println(env["foo"])
}Source: joho/godotenv