From 06ca74c16575f1b20a69df1f3c791cf675e7d2b2 Mon Sep 17 00:00:00 2001 From: Mradul Singh Date: Thu, 26 Nov 2026 08:50:20 +0530 Subject: [PATCH] Do not turn \n and \t into escapes in quoted keys --- Tomlet.Tests/BasicKeyValueTests.cs | 13 +++++++++++++ Tomlet/TomlParser.cs | 3 --- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Tomlet.Tests/BasicKeyValueTests.cs b/Tomlet.Tests/BasicKeyValueTests.cs index 05d94b6..10fb898 100644 --- a/Tomlet.Tests/BasicKeyValueTests.cs +++ b/Tomlet.Tests/BasicKeyValueTests.cs @@ -155,5 +155,18 @@ public void EmptyKeyNamesAreLegalIfQuoted() Assert.Equal("", doc.Entries.Keys.First()); Assert.Equal("blank", Assert.IsType(doc.Entries[""]).Value); } + + [Fact] + public void BackslashesInQuotedKeysAreNotTurnedIntoEscapes() + { + var doc = GetDocument("'C:\\new' = 1\n'C:\\tools' = 2\n\"C:\\\\temp\" = 3\n\"tab\\there\" = 4"); + + Assert.Collection(doc.Entries.Keys, + key1 => Assert.Equal("C:\\new", key1), + key2 => Assert.Equal("C:\\tools", key2), + key3 => Assert.Equal("C:\\temp", key3), + key4 => Assert.Equal("tab\there", key4) + ); + } } } \ No newline at end of file diff --git a/Tomlet/TomlParser.cs b/Tomlet/TomlParser.cs index cd30b37..5645814 100644 --- a/Tomlet/TomlParser.cs +++ b/Tomlet/TomlParser.cs @@ -174,9 +174,6 @@ private string ReadKey(TomletStringReader reader) //Read unquoted key key = ReadKeyInternal(reader, keyChar => keyChar.IsEquals() || keyChar.IsHashSign()); - key = key.Replace("\\n", "\n") - .Replace("\\t", "\t"); - return key; }