Skip to content

Getting a string value does not work if the value contains a backslash ( \ ) #2

Description

@maj-o

strconv.Unquote( ""abc\def"" ) produces an error

func getString(values map[string]interface{}, key string, def string) string {
val := get(values, key)
if val != nil {
str, err := strconv.Unquote(fmt.Sprintf(""%v"", val))
if err == nil {
return str
}
return def
}
return def
}

This works for me:

func getString(values map[string]interface{}, key string, def string) string {
val := get(values, key)
if val != nil {
str := fmt.Sprintf("%v", val)
if len(str) > 0 {
return str
}
return def
}
return def
}

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