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

Commit

Permalink
Quoted style for string consisting of digits with leading zero
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 20, 2023
1 parent cd1fd90 commit a38768f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,12 @@ where
Ok(ScalarStyle::SingleQuoted)
}

fn visit_str<E>(self, _v: &str) -> Result<Self::Value, E> {
Ok(ScalarStyle::Any)
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> {
Ok(if crate::de::digits_but_not_number(v) {
ScalarStyle::SingleQuoted
} else {
ScalarStyle::Any
})
}

fn visit_unit<E>(self) -> Result<Self::Value, E> {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ fn test_strings_needing_quote() {
boolean: 'true'
integer: '1'
void: 'null'
leading_zeros: 007
leading_zeros: '007'
"#};
test_serde(&thing, yaml);
}
Expand Down

0 comments on commit a38768f

Please sign in to comment.