Skip to content

Commit

Permalink
Don't allow "0_0"
Browse files Browse the repository at this point in the history
Leading zeros wouldn't be detected as the second character isn't a
digit. Make this check more specific to test for 'b', 'o', and 'x'
specifically.

Fixes #326
  • Loading branch information
arp242 committed Nov 25, 2021
1 parent 847ee8a commit b1471ff
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
2 changes: 1 addition & 1 deletion parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (p *parser) valueInlineTable(it item, parentIsArray bool) (interface{}, tom
// numHasLeadingZero checks if this number has leading zeroes, allowing for '0',
// +/- signs, and base prefixes.
func numHasLeadingZero(s string) bool {
if len(s) > 1 && s[0] == '0' && isDigit(rune(s[1])) { // >1 to allow "0" and isDigit to allow 0x
if len(s) > 1 && s[0] == '0' && !(s[1] == 'b' || s[1] == 'o' || s[1] == 'x') { // Allow 0b, 0o, 0x
return true
}
if len(s) > 2 && (s[0] == '-' || s[0] == '+') && s[1] == '0' {
Expand Down
1 change: 0 additions & 1 deletion toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ func TestToml(t *testing.T) {
"invalid/datetime/time-no-leads", // https://github.com/BurntSushi/toml/issues/320
"invalid/control/bare-null", // https://github.com/BurntSushi/toml/issues/317
"invalid/control/comment-cr", // https://github.com/BurntSushi/toml/issues/321
"invalid/integer/leading-zero-3", // https://github.com/BurntSushi/toml/issues/326
"invalid/string/multiline-bad-escape-3", // https://github.com/BurntSushi/toml/issues/322
},
}
Expand Down

0 comments on commit b1471ff

Please sign in to comment.