Skip to content

Commit

Permalink
fix(encode): Correct encoding for key with mixed quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 17, 2024
1 parent 82c0195 commit 0b268f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 4 additions & 1 deletion crates/toml_edit/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ fn infer_style(
match (style, literal) {
(Some(style), Some(literal)) => (style, literal),
(None, Some(literal)) => (infer_all_style(value).0, literal),
(Some(style), None) => (style, infer_all_style(value).1),
(Some(style), None) => {
let literal = !value.contains('\'') && (value.contains('"') | value.contains('\\'));
(style, literal)
}
(None, None) => infer_all_style(value),
}
}
Expand Down
4 changes: 1 addition & 3 deletions crates/toml_edit/tests/testsuite/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1834,12 +1834,10 @@ fn key_value_roundtrip() {
r#""squoted 'content' squoted""#,
str![[r#""squoted 'content' squoted""#]],
);
/*
assert_key_value_roundtrip(
r#""mixed quoted \"start\" 'end'' mixed quote""#,
str![[r#""squoted 'content' squoted""#]],
str![[r#""mixed quoted /"start/" 'end'' mixed quote""#]],
);
*/
}

#[track_caller]
Expand Down

0 comments on commit 0b268f2

Please sign in to comment.