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 705e2d5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
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 705e2d5

Please sign in to comment.