From e78ccff9a47bba455b4339f40ddd9991c7256684 Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Tue, 23 Mar 2021 09:02:48 -0400 Subject: [PATCH] Fix parsing integer 0 --- README.md | 2 +- .../imported_tests/unmarshal_imported_test.go | 2 +- parser.go | 18 +++++++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 158313c..b077e97 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Development branch. Probably does not work. - [x] Unmarshal into maps. - [x] Support Array Tables. -- [x] Unmarshal into pointers. +- [x] Unmarshal into pointers. - [x] Support Date / times. - [ ] Support Unmarshaler interface. - [x] Support struct tags annotations. diff --git a/internal/imported_tests/unmarshal_imported_test.go b/internal/imported_tests/unmarshal_imported_test.go index d970dbb..1ea19c4 100644 --- a/internal/imported_tests/unmarshal_imported_test.go +++ b/internal/imported_tests/unmarshal_imported_test.go @@ -439,7 +439,7 @@ func TestEmptytomlUnmarshal(t *testing.T) { String: "", StringList: []string{}, Ptr: nil, - Map: map[string]string{}, + Map: nil, } result := emptyMarshalTestStruct{} diff --git a/parser.go b/parser.go index 289bb15..ce45e55 100644 --- a/parser.go +++ b/parser.go @@ -977,17 +977,21 @@ func (p *parser) scanIntOrFloat(node *ast.Node, b []byte) ([]byte, error) { case 'b': isValidRune = isValidBinaryRune default: - return b, fmt.Errorf("unknown number base: %c. possible options are x (hex) o (octal) b (binary)", b[1]) + i++ } - i += 2 - for ; i < len(b); i++ { - if !isValidRune(b[i]) { - node.Kind = ast.Integer - node.Data = b[:i] - return b[i:], nil + if isValidRune != nil { + i += 2 + for ; i < len(b); i++ { + if !isValidRune(b[i]) { + break + } } } + + node.Kind = ast.Integer + node.Data = b[:i] + return b[i:], nil } isFloat := false