Fix string regression in attribute parsing (#2759)
In #2721, the ability for key-only values was added via using a wrapperspb.StringValue that could be null. This introduced a bug because originally the default case for `-attr` was to get the string value but instead it used the incoming value as-is to allow for nulls; the null check was moved up later but the original behavior was not restored. As a result, non-explicitly-quoted strings carried through the wrapperspb.StringValue, resulting in a map for the value in JSON instead of a string. This also fixes the ability to set explicitly quoted strings.
This commit is contained in:
1 parent
9135cc7668
commit
b286060ea8
3 files changed
+48
-18
No files matched your search
@@ -288,7 +288,7 @@ func HandleAttributeFlags(c *base.Command, suffix, fullField string, sepFields [
|
||||
if field.Value == nil {
|
||||
return fmt.Errorf("string-%s flag requires a value", suffix)
|
||||
}
|
||||
val = strings.Trim(field.Value.GetValue(), `"`)
|
||||
val = field.Value.GetValue()
|
||||
|
||||
case "bool-" + suffix:
|
||||
if field.Value == nil {
|
||||
@@ -318,9 +318,6 @@ func HandleAttributeFlags(c *base.Command, suffix, fullField string, sepFields [
|
||||
case field.Value.GetValue() == "false": // bool false
|
||||
val = false
|
||||
|
||||
case strings.HasPrefix(field.Value.GetValue(), `"`): // explicitly quoted string
|
||||
val = strings.Trim(field.Value.GetValue(), `"`)
|
||||
|
||||
case jsonNumberRegex.MatchString(strings.Trim(field.Value.GetValue(), `"`)): // number
|
||||
// Same logic as above
|
||||
if strings.Contains(field.Value.GetValue(), ".") {
|
||||
@@ -355,7 +352,7 @@ func HandleAttributeFlags(c *base.Command, suffix, fullField string, sepFields [
|
||||
|
||||
default:
|
||||
// Default is to treat as a string value
|
||||
val = field.Value
|
||||
val = field.Value.GetValue()
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
Reference in new issue
Block a user