Skip to content

Commit

Permalink
Fix too-lax bool lexing
Browse files Browse the repository at this point in the history
  • Loading branch information
cespare committed Mar 28, 2017
1 parent d94612f commit b26d9c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,34 @@ func TestDecodeErrors(t *testing.T) {
}
}

// Test for https://github.com/BurntSushi/toml/pull/166.
func TestDecodeBoolArray(t *testing.T) {
for _, tt := range []struct {
s string
got interface{}
want interface{}
}{
{
"a = [true, false]",
&struct{ A []bool }{},
&struct{ A []bool }{[]bool{true, false}},
},
{
"a = {a = true, b = false}",
&struct{ A map[string]bool }{},
&struct{ A map[string]bool }{map[string]bool{"a": true, "b": false}},
},
} {
if _, err := Decode(tt.s, tt.got); err != nil {
t.Errorf("Decode(%q): %s", tt.s, err)
continue
}
if !reflect.DeepEqual(tt.got, tt.want) {
t.Errorf("Decode(%q): got %#v; want %#v", tt.s, tt.got, tt.want)
}
}
}

func ExampleMetaData_PrimitiveDecode() {
var md MetaData
var err error
Expand Down
2 changes: 1 addition & 1 deletion lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ func lexBool(lx *lexer) stateFn {
var rs []rune
for {
r := lx.next()
if r == eof || isWhitespace(r) || isNL(r) {
if !unicode.IsLetter(r) {
lx.backup()
break
}
Expand Down

0 comments on commit b26d9c3

Please sign in to comment.