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

(possible) bug in parser right-trimming escaped quotes? #226

Open
monerowner opened this issue Feb 17, 2024 · 0 comments
Open

(possible) bug in parser right-trimming escaped quotes? #226

monerowner opened this issue Feb 17, 2024 · 0 comments

Comments

@monerowner
Copy link

monerowner commented Feb 17, 2024

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"])
}
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

1 participant