spf13 / pflag

Drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags.
BSD 3-Clause "New" or "Revised" License
2.43k stars 348 forks source link

Quotes not preserved in flags of type StringToString #390

Open octachrome opened 1 year ago

octachrome commented 1 year ago

When the program below is run with go run ./main.go --sts 'key="495"' I get map[string]string{"key":"\"123"}, where only one double quote has been trimmed from the value. I don't see anything in the documentation about quote handling, so I would expect quotes to be preserved here: map[string]string{"key":"\"123\""}.

package main

import (
    "fmt"
    "os"

    "github.com/spf13/pflag"
)

func main() {
    fs := pflag.NewFlagSet("Example", pflag.PanicOnError)
    fs.StringToString("sts", make(map[string]string), "")
    _ = fs.Parse(os.Args)
    sts, err := fs.GetStringToString("sts")
    if err != nil {
        panic(err)
    }
    fmt.Printf("%#v\n", sts)
}