From 0b268f20c11003de0fe2a886d15816fba41f4ed3 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 17 Jul 2024 11:01:57 -0500 Subject: [PATCH] fix(encode): Correct encoding for key with mixed quotes --- crates/toml_edit/src/encode.rs | 5 ++++- crates/toml_edit/tests/testsuite/parse.rs | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/toml_edit/src/encode.rs b/crates/toml_edit/src/encode.rs index 8065e18a..420aa754 100644 --- a/crates/toml_edit/src/encode.rs +++ b/crates/toml_edit/src/encode.rs @@ -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), } } diff --git a/crates/toml_edit/tests/testsuite/parse.rs b/crates/toml_edit/tests/testsuite/parse.rs index a576a3ea..62b33bdd 100644 --- a/crates/toml_edit/tests/testsuite/parse.rs +++ b/crates/toml_edit/tests/testsuite/parse.rs @@ -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]