Skip to content

Commit eb5c8c8

Browse files
Disallow empty value in list.
$ echo "x [a, , b]" | blaze-bin/third_party/txtpbfmt/fmt parser.Format for path <stdin> with content "x [a, , b]\n" returned err Empty value in list. F0428 14:10:56.453731 680717 fmt.go:103] 1 error(s) encountered during execution Note that this doesn't prevent empty strings: $ echo "x [a, '' , b]" | blaze-bin/third_party/txtpbfmt/fmt x [a, "", b] PiperOrigin-RevId: 445142675
1 parent 8830a50 commit eb5c8c8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

parser/parser.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,10 @@ func (p *parser) parse(isRoot bool) (result []*ast.Node, endPos ast.Position, er
714714
return nil, ast.Position{}, err
715715
}
716716
if len(vals) != 1 {
717-
return nil, ast.Position{}, fmt.Errorf("multiple-string value not supported (%v). Please add comma explcitily, see http://b/162070952", vals)
717+
return nil, ast.Position{}, fmt.Errorf("multiple-string value not supported (%v). Please add comma explicitly, see http://b/162070952", vals)
718+
}
719+
if len(vals[0].Value) == 0 {
720+
return nil, ast.Position{}, fmt.Errorf("empty value in list")
718721
}
719722
vals[0].PreComments = append(vals[0].PreComments, preComments...)
720723

parser/parser_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ func TestError(t *testing.T) {
2626
}, {
2727
in: `name: "string with literal new line
2828
"`, err: "new line",
29+
}, {
30+
in: `list_with_empty_list: [a,,b]`, err: "empty value in list",
2931
}}
3032
for _, input := range inputs {
3133
out, err := Format([]byte(input.in))

0 commit comments

Comments
 (0)