Skip to content

Commit

Permalink
Merge pull request #972 from jcbfaulks/no_quote_backslash
Browse files Browse the repository at this point in the history
Prevent forced quoting of strings with leading backslash
+semver:fix
  • Loading branch information
EdwardCooke committed Sep 11, 2024
2 parents aa9be23 + 42f684d commit 1127009
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions YamlDotNet.Test/Core/EmitterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,16 @@ public void SingleQuotesAreNotDoubleQuotedUnlessNecessary(string input)
yaml.Should().NotContain("\"");
}

[Theory]
[InlineData(@"\hello world")]
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)
{
return string.Join(Environment.NewLine, lines);
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/Core/Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private void AnalyzeScalar(Scalar scalar)
{
if (isFirst)
{
if (buffer.Check(@"#,[]{}&*!|>\""%@`'"))
if (buffer.Check(@"#,[]{}&*!|>""%@`'"))
{
flowIndicators = true;
blockIndicators = true;
Expand Down

0 comments on commit 1127009

Please sign in to comment.