Skip to content

Commit

Permalink
Disallow empty value in list.
Browse files Browse the repository at this point in the history
$ 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
  • Loading branch information
txtpbfmt-copybara-robot committed Apr 28, 2022
1 parent 8830a50 commit eb5c8c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,10 @@ func (p *parser) parse(isRoot bool) (result []*ast.Node, endPos ast.Position, er
return nil, ast.Position{}, err
}
if len(vals) != 1 {
return nil, ast.Position{}, fmt.Errorf("multiple-string value not supported (%v). Please add comma explcitily, see http://b/162070952", vals)
return nil, ast.Position{}, fmt.Errorf("multiple-string value not supported (%v). Please add comma explicitly, see http://b/162070952", vals)
}
if len(vals[0].Value) == 0 {
return nil, ast.Position{}, fmt.Errorf("empty value in list")
}
vals[0].PreComments = append(vals[0].PreComments, preComments...)

Expand Down
2 changes: 2 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func TestError(t *testing.T) {
}, {
in: `name: "string with literal new line
"`, err: "new line",
}, {
in: `list_with_empty_list: [a,,b]`, err: "empty value in list",
}}
for _, input := range inputs {
out, err := Format([]byte(input.in))
Expand Down

0 comments on commit eb5c8c8

Please sign in to comment.