Skip to content

Commit

Permalink
Support zero args in variadic properties
Browse files Browse the repository at this point in the history
  • Loading branch information
knz committed Sep 3, 2022
1 parent f085409 commit 35a78f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,12 @@ func (p prop) assign(dst S, args string) (S, error) {
vals = append(vals, reflect.ValueOf(dst))
pos := 0
input := []byte(args)
for _, arg := range p.args {
for i, arg := range p.args {
if pos >= len(input) {
if p.isVariadic && i == len(p.args)-1 {
// It's ok for a variadic arg list to have zero argument.
break
}
return dst, fmt.Errorf("missing value")
}
var err error
Expand Down
12 changes: 12 additions & 0 deletions convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ border-bottom-size: 1;
border-style: border("a","b","c","d","e","f","g","h");
border-top: true;
border-top-width: 1;`, ``},
{emptyStyle,
`border: border("a","b","c","d","e","f","g","h")`,
`border-bottom: true;
border-bottom-size: 1;
border-left: true;
border-left-size: 1;
border-right: true;
border-right-size: 1;
border-style: border("a","b","c","d","e","f","g","h");
border-top: true;
border-top-width: 1;`,
``},
{emptyStyle,
`border: border("a","b","c","d","e","f","g","h") true xx`,
``,
Expand Down

0 comments on commit 35a78f5

Please sign in to comment.