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

Commit

Permalink
Touch up PR 180
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 31, 2020
1 parent ce23aff commit ed53e36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,11 @@ 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) {
if v.len() > 1 && v.starts_with('0') && v.bytes().all(|b| b.is_ascii_digit()) {
// 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
return visitor.visit_str(v);
}
if let Ok(n) = v.parse() {
Expand Down
9 changes: 6 additions & 3 deletions tests/test_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ 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)));
assert_eq!(pos_nan, different_pos_nan);
}

#[test]
fn test_digits() {
let num_string = serde_yaml::from_str::<Value>("01").unwrap();
assert!(num_string.is_string());
}

0 comments on commit ed53e36

Please sign in to comment.