Skip to content

Commit

Permalink
Merge pull request #26 from nyctef/string-literal-multi-crlf
Browse files Browse the repository at this point in the history
allow windows (crlf) newlines in IsSafeStringLiteralMulti
  • Loading branch information
xoofx authored Feb 25, 2022
2 parents 477d573 + 548b78d commit 9d55470
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/Tomlyn.Tests/SerializationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.

using NUnit.Framework;
using Tomlyn.Model;

namespace Tomlyn.Tests
{
public class SerializationTests
{
[Test]
public void TestCrlfInMultilineString()
{
var model = new TomlTable
{
PropertiesMetadata = new TomlPropertiesMetadata()
};
model.PropertiesMetadata.SetProperty("property", new TomlPropertyMetadata
{
DisplayKind = TomlPropertyDisplayKind.StringLiteralMulti
});

model["property"] = "string\r\nwith\r\nnewlines";

Assert.AreEqual("property = '''string\r\nwith\r\nnewlines'''\r\n", Toml.FromModel(model));
}
}
}
2 changes: 1 addition & 1 deletion src/Tomlyn/Helpers/TomlFormatHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private static bool IsSafeStringLiteralMulti(string text)
{
var c = text[i];
// new line are permitted
if ((c == '\r' && i + 1 < text.Length && text[i + 1] == 'n') || c == '\n')
if ((c == '\r' && i + 1 < text.Length && text[i + 1] == '\n') || c == '\n')
{
continue;
}
Expand Down

0 comments on commit 9d55470

Please sign in to comment.