Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow windows (crlf) newlines in IsSafeStringLiteralMulti #26

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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