diff --git a/cmd/libs/go2idl/types/comments.go b/cmd/libs/go2idl/types/comments.go index 92980e49fc6..8150c383875 100644 --- a/cmd/libs/go2idl/types/comments.go +++ b/cmd/libs/go2idl/types/comments.go @@ -25,16 +25,18 @@ import ( // ExtractCommentTags parses comments for lines of the form: // -// 'marker' + "key1=value1,key2=value2". +// 'marker' + "key=value". // // Values are optional; "" is the default. A tag can be specified more than // one time and all values are returned. If the resulting map has an entry for // a key, the value (a slice) is guaranteed to have at least 1 element. // -// Example: if you pass "+" for 'marker', and the following two lines are in +// Example: if you pass "+" for 'marker', and the following lines are in // the comments: -// +foo=value1,bar -// +foo=value2,baz="qux" +// +foo=value1 +// +bar +// +foo=value2 +// +baz="qux" // Then this function will return: // map[string][]string{"foo":{"value1, "value2"}, "bar": {""}, "baz": {"qux"}} func ExtractCommentTags(marker string, lines []string) map[string][]string { @@ -47,14 +49,12 @@ func ExtractCommentTags(marker string, lines []string) map[string][]string { if !strings.HasPrefix(line, marker) { continue } - pairs := strings.Split(line[len(marker):], ",") - for _, p := range pairs { - kv := strings.Split(p, "=") - if len(kv) == 2 { - out[kv[0]] = append(out[kv[0]], kv[1]) - } else if len(kv) == 1 { - out[kv[0]] = append(out[kv[0]], "") - } + // TODO: we could support multiple values per key if we split on spaces + kv := strings.SplitN(line[len(marker):], "=", 2) + if len(kv) == 2 { + out[kv[0]] = append(out[kv[0]], kv[1]) + } else if len(kv) == 1 { + out[kv[0]] = append(out[kv[0]], "") } } return out diff --git a/cmd/libs/go2idl/types/comments_test.go b/cmd/libs/go2idl/types/comments_test.go index a498156f8ee..161f4a6e98c 100644 --- a/cmd/libs/go2idl/types/comments_test.go +++ b/cmd/libs/go2idl/types/comments_test.go @@ -25,12 +25,18 @@ import ( func TestExtractCommentTags(t *testing.T) { commentLines := []string{ "Human comment that is ignored.", - "+foo=value1,bar", - "+foo=value2,baz=qux", + "+foo=value1", + "+bar", + "+foo=value2", + "+baz=qux,zrb=true", } a := ExtractCommentTags("+", commentLines) - e := map[string][]string{"foo": {"value1", "value2"}, "bar": {""}, "baz": {"qux"}} + e := map[string][]string{ + "foo": {"value1", "value2"}, + "bar": {""}, + "baz": {"qux,zrb=true"}, + } if !reflect.DeepEqual(e, a) { t.Errorf("Wanted %q, got %q", e, a) }