Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #180 from panoptix-za/master
Browse files Browse the repository at this point in the history
Add a check for strings disguised as leading zeros followed by numbers
  • Loading branch information
dtolnay committed Oct 31, 2020
2 parents f208925 + 7b44a8e commit ce23aff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/de.rs
Expand Up @@ -556,6 +556,13 @@ where
return visitor.visit_i64(n);
}
}
// After handling the different number encodings above
// if we are left with leading zero(s) followed by numeric characters
// this is in fact a string according to the YAML 1.2 spec
// https://yaml.org/spec/1.2/spec.html#id2761292
if v.len() > 1 && v.starts_with('0') && v.chars().all(char::is_numeric) {
return visitor.visit_str(v);
}
if let Ok(n) = v.parse() {
return visitor.visit_u64(n);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/test_value.rs
Expand Up @@ -10,6 +10,9 @@ fn test_nan() {
let neg_fake_nan = serde_yaml::from_str::<Value>("-.nan").unwrap();
assert!(neg_fake_nan.is_string());

let num_string = serde_yaml::from_str::<Value>("01").unwrap();
assert!(num_string.is_string());

let significand_mask = 0xF_FFFF_FFFF_FFFF;
let bits = (f64::NAN.to_bits() ^ significand_mask) | 1;
let different_pos_nan = Value::Number(Number::from(f64::from_bits(bits)));
Expand Down

0 comments on commit ce23aff

Please sign in to comment.