Skip to content

Commit b1471ff

Browse files
committed
Don't allow "0_0"
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
1 parent 847ee8a commit b1471ff

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func (p *parser) valueInlineTable(it item, parentIsArray bool) (interface{}, tom
425425
// numHasLeadingZero checks if this number has leading zeroes, allowing for '0',
426426
// +/- signs, and base prefixes.
427427
func numHasLeadingZero(s string) bool {
428-
if len(s) > 1 && s[0] == '0' && isDigit(rune(s[1])) { // >1 to allow "0" and isDigit to allow 0x
428+
if len(s) > 1 && s[0] == '0' && !(s[1] == 'b' || s[1] == 'o' || s[1] == 'x') { // Allow 0b, 0o, 0x
429429
return true
430430
}
431431
if len(s) > 2 && (s[0] == '-' || s[0] == '+') && s[1] == '0' {

toml_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ func TestToml(t *testing.T) {
289289
"invalid/datetime/time-no-leads", // https://github.com/BurntSushi/toml/issues/320
290290
"invalid/control/bare-null", // https://github.com/BurntSushi/toml/issues/317
291291
"invalid/control/comment-cr", // https://github.com/BurntSushi/toml/issues/321
292-
"invalid/integer/leading-zero-3", // https://github.com/BurntSushi/toml/issues/326
293292
"invalid/string/multiline-bad-escape-3", // https://github.com/BurntSushi/toml/issues/322
294293
},
295294
}

0 commit comments

Comments
 (0)