Skip to content

Commit

Permalink
Allow zero-padded numbers in identifiers
Browse files Browse the repository at this point in the history
According to the toml standard [0], bare keys may only contain the
characters A-Za-z0-9_- and are explicitly allowed to be composed of only
ASCII digits. Keys are always interpreted as strings.

The standard does not forbid number-like keys starting with zero.

[0]: https://toml.io/en/v1.0.0#keys
  • Loading branch information
Garmelon committed Feb 20, 2025
1 parent 18b86da commit e398abd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 1 addition & 3 deletions crates/taplo/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,7 @@ impl<'p> Parser<'p> {
}
}
FLOAT => {
if self.lexer.slice().starts_with('0') {
self.error("zero-padded numbers are not allowed")
} else if self.lexer.slice().starts_with('+') {
if self.lexer.slice().starts_with('+') {
Err(())
} else {
for (i, s) in self.lexer.slice().split('.').enumerate() {
Expand Down
12 changes: 12 additions & 0 deletions crates/taplo/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ fn comments_after_tables() {

assert!(errors.is_empty(), "{:#?}", errors);
}

#[test]
fn digits_in_keys() {
let src = r#"
0123 = true
01.23 = true
23.01 = true
"#;
let errors = parse(src).errors;

assert!(errors.is_empty(), "{:#?}", errors);
}

0 comments on commit e398abd

Please sign in to comment.