Skip to content

Commit

Permalink
fix(encode): Prefer literals over escaping double-quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 3, 2024
1 parent 42f7a1b commit c9e36e7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/toml/tests/testsuite/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn table() {
}
.to_string(),
"\"foo.bar\" = 2\n\
\"foo\\\"bar\" = 2\n"
'foo\"bar' = 2\n"
);
assert_eq!(
map! {
Expand Down
3 changes: 3 additions & 0 deletions crates/toml_edit/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ fn infer_style(value: &str) -> (StringStyle, bool) {
}
match ch {
'\t' => {}
'"' => {
prefer_literal = true;
}
'\\' => {
prefer_literal = true;
}
Expand Down
8 changes: 2 additions & 6 deletions crates/toml_edit/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,13 @@ fn to_key_repr(key: &str) -> Repr {
crate::encode::to_string_repr(
key,
Some(crate::encode::StringStyle::OnelineSingle),
Some(false),
None,
)
}
}
#[cfg(not(feature = "parse"))]
{
crate::encode::to_string_repr(
key,
Some(crate::encode::StringStyle::OnelineSingle),
Some(false),
)
crate::encode::to_string_repr(key, Some(crate::encode::StringStyle::OnelineSingle), None)
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/toml_edit/tests/testsuite/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ fn test_insert_key_with_quotes() {
[target]
[target."cfg(target_os = \"linux\")"]
[target.'cfg(target_os = "linux")']
[target."cfg(target_os = \"linux\")".dependencies]
[target.'cfg(target_os = "linux")'.dependencies]
name = "dep"
"#]]);
Expand Down

0 comments on commit c9e36e7

Please sign in to comment.