Skip to content

FlagSet.GetStringToString() drops brackets from values #413

Description

@lstemplinger

Code Example:

package main

import (
	"fmt"

	"github.com/spf13/pflag"
)

func main() {
	fs := pflag.NewFlagSet("test", pflag.PanicOnError)
	fs.StringToString("testflag", map[string]string{}, "")
	fs.Set("testflag", "x=[]")
	fmt.Println(fs.Lookup("testflag").Value.String())
	result, _ := fs.GetStringToString("testflag")
	fmt.Println(result)
}

With pflag Version 1.0.5 the output is:

[x=[]]    
map[x:] 

I would have expected:

[x=[]]    
map[x:[]] 

Looking at the code, it looks like the Trim() here also removes brackets at the end of the flag value, not just those added by String(): https://github.com/spf13/pflag/blob/master/string_to_string.go#L80

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions