From 425ba572b1a4c0e2bf9f0af63c92482a6574365a Mon Sep 17 00:00:00 2001 From: Jacob Faulks Date: Fri, 6 Sep 2024 09:58:56 -0500 Subject: [PATCH 1/3] failed test --- YamlDotNet.Test/Core/EmitterTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/YamlDotNet.Test/Core/EmitterTests.cs b/YamlDotNet.Test/Core/EmitterTests.cs index aa7fe34c7..66c3b52ba 100644 --- a/YamlDotNet.Test/Core/EmitterTests.cs +++ b/YamlDotNet.Test/Core/EmitterTests.cs @@ -443,6 +443,15 @@ public void SingleQuotesAreNotDoubleQuotedUnlessNecessary(string input) yaml.Should().NotContain("\""); } + [Theory] + [InlineData(@"\hello world")] + public void LeadingBackslashIsNotQuotedUnlessNecessary(string input) + { + var events = StreamOf(DocumentWith(new Scalar(input))); + var yaml = EmittedTextFrom(events); + yaml.Should().NotContain("\'"); + } + private string Lines(params string[] lines) { return string.Join(Environment.NewLine, lines); From 600b58654ebac90943b209553e912b632c98857b Mon Sep 17 00:00:00 2001 From: Jacob Faulks Date: Fri, 6 Sep 2024 10:10:27 -0500 Subject: [PATCH 2/3] remove backslash from emitter check --- YamlDotNet.Test/Core/EmitterTests.cs | 2 +- YamlDotNet/Core/Emitter.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/YamlDotNet.Test/Core/EmitterTests.cs b/YamlDotNet.Test/Core/EmitterTests.cs index 66c3b52ba..ae9ab6871 100644 --- a/YamlDotNet.Test/Core/EmitterTests.cs +++ b/YamlDotNet.Test/Core/EmitterTests.cs @@ -445,7 +445,7 @@ public void SingleQuotesAreNotDoubleQuotedUnlessNecessary(string input) [Theory] [InlineData(@"\hello world")] - public void LeadingBackslashIsNotQuotedUnlessNecessary(string input) + public void LeadingBackslashIsNotQuoted(string input) { var events = StreamOf(DocumentWith(new Scalar(input))); var yaml = EmittedTextFrom(events); diff --git a/YamlDotNet/Core/Emitter.cs b/YamlDotNet/Core/Emitter.cs index 154420822..dc786e05e 100644 --- a/YamlDotNet/Core/Emitter.cs +++ b/YamlDotNet/Core/Emitter.cs @@ -340,7 +340,7 @@ private void AnalyzeScalar(Scalar scalar) { if (isFirst) { - if (buffer.Check(@"#,[]{}&*!|>\""%@`'")) + if (buffer.Check(@"#,[]{}&*!|>""%@`'")) { flowIndicators = true; blockIndicators = true; From 42f684dab17c09d1b3a31dcf89b12ac6f708a548 Mon Sep 17 00:00:00 2001 From: Jacob Faulks Date: Fri, 6 Sep 2024 10:12:38 -0500 Subject: [PATCH 3/3] test for both single and double quotes --- YamlDotNet.Test/Core/EmitterTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/YamlDotNet.Test/Core/EmitterTests.cs b/YamlDotNet.Test/Core/EmitterTests.cs index ae9ab6871..9b28bb2a3 100644 --- a/YamlDotNet.Test/Core/EmitterTests.cs +++ b/YamlDotNet.Test/Core/EmitterTests.cs @@ -450,6 +450,7 @@ public void LeadingBackslashIsNotQuoted(string input) var events = StreamOf(DocumentWith(new Scalar(input))); var yaml = EmittedTextFrom(events); yaml.Should().NotContain("\'"); + yaml.Should().NotContain("\""); } private string Lines(params string[] lines)