Skip to content

Commit

Permalink
fix extra carriage return in Key::String value with serde_yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
glehmann committed Feb 1, 2024
1 parent 3177d4a commit 4ad230f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
11 changes: 3 additions & 8 deletions src/value/serde_yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ impl Value for SerdeYaml {
inner.iter().enumerate().map(|(i, v)| (Key::Index(i), v)),
)),
SerdeYaml::Mapping(ref inner) => Some(Box::new(inner.iter().map(|(k, v)| {
(
Key::String(
to_string(k)
.expect("yaml value to serialize into yaml correctly")
.to_owned(),
),
v,
)
let k = to_string(k).expect("yaml value to serialize into yaml correctly");
let k = &k[..k.len() - 1]; // trim trailing carriage return
(Key::String(k.to_owned()), v)
}))),
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/json_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ mod serde_yaml {
assert_eq!(
j.items().unwrap().collect::<Vec<_>>(),
vec![
(Key::String("a\n".into()), &ValueType::Null),
(Key::String("b\n".into()), &ValueType::Bool(true))
(Key::String("a".into()), &ValueType::Null),
(Key::String("b".into()), &ValueType::Bool(true))
]
);
}
Expand Down

0 comments on commit 4ad230f

Please sign in to comment.