Skip to content

Commit c9e36e7

Browse files
committed
fix(encode): Prefer literals over escaping double-quotes
Part of rust-lang/cargo#14002
1 parent 42f7a1b commit c9e36e7

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

crates/toml/tests/testsuite/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn table() {
7575
}
7676
.to_string(),
7777
"\"foo.bar\" = 2\n\
78-
\"foo\\\"bar\" = 2\n"
78+
'foo\"bar' = 2\n"
7979
);
8080
assert_eq!(
8181
map! {

crates/toml_edit/src/encode.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ fn infer_style(value: &str) -> (StringStyle, bool) {
439439
}
440440
match ch {
441441
'\t' => {}
442+
'"' => {
443+
prefer_literal = true;
444+
}
442445
'\\' => {
443446
prefer_literal = true;
444447
}

crates/toml_edit/src/key.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,13 @@ fn to_key_repr(key: &str) -> Repr {
289289
crate::encode::to_string_repr(
290290
key,
291291
Some(crate::encode::StringStyle::OnelineSingle),
292-
Some(false),
292+
None,
293293
)
294294
}
295295
}
296296
#[cfg(not(feature = "parse"))]
297297
{
298-
crate::encode::to_string_repr(
299-
key,
300-
Some(crate::encode::StringStyle::OnelineSingle),
301-
Some(false),
302-
)
298+
crate::encode::to_string_repr(key, Some(crate::encode::StringStyle::OnelineSingle), None)
303299
}
304300
}
305301

crates/toml_edit/tests/testsuite/edit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ fn test_insert_key_with_quotes() {
222222
223223
[target]
224224
225-
[target."cfg(target_os = \"linux\")"]
225+
[target.'cfg(target_os = "linux")']
226226
227-
[target."cfg(target_os = \"linux\")".dependencies]
227+
[target.'cfg(target_os = "linux")'.dependencies]
228228
name = "dep"
229229
230230
"#]]);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy