diff --git a/src/ser.rs b/src/ser.rs index 4dbd0c35..23c761bb 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -339,8 +339,12 @@ where Ok(ScalarStyle::SingleQuoted) } - fn visit_str(self, _v: &str) -> Result { - Ok(ScalarStyle::Any) + fn visit_str(self, v: &str) -> Result { + Ok(if crate::de::digits_but_not_number(v) { + ScalarStyle::SingleQuoted + } else { + ScalarStyle::Any + }) } fn visit_unit(self) -> Result { diff --git a/tests/test_serde.rs b/tests/test_serde.rs index cf8d5e9b..d332df40 100644 --- a/tests/test_serde.rs +++ b/tests/test_serde.rs @@ -299,16 +299,19 @@ fn test_strings_needing_quote() { boolean: String, integer: String, void: String, + leading_zeros: String, } let thing = Struct { boolean: "true".to_owned(), integer: "1".to_owned(), void: "null".to_owned(), + leading_zeros: "007".to_owned(), }; let yaml = indoc! {r#" boolean: 'true' integer: '1' void: 'null' + leading_zeros: '007' "#}; test_serde(&thing, yaml); }