From 41b399bb774dff2c052754b2b89753248259b96d Mon Sep 17 00:00:00 2001 From: rboy1 <3846367+rboy1@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:54:24 -0400 Subject: [PATCH 1/4] Fix for handling comments --- Src/ConfigurationReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/ConfigurationReader.cs b/Src/ConfigurationReader.cs index 369b207..56d6692 100644 --- a/Src/ConfigurationReader.cs +++ b/Src/ConfigurationReader.cs @@ -58,7 +58,7 @@ private static void Parse(StringReader reader, Configuration config) } string lineWithoutComment = line; - if (commentIndex > 0) + if (!Configuration.IgnoreInlineComments && commentIndex > 0) { lineWithoutComment = line.Remove(commentIndex).Trim(); // remove inline comment } From 6f42624d1faaff3454099445bdc85de0db063b56 Mon Sep 17 00:00:00 2001 From: rboy1 <3846367+rboy1@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:55:18 -0400 Subject: [PATCH 2/4] Fix for handling comments --- Src/Setting.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/Setting.cs b/Src/Setting.cs index 035065b..796e76e 100644 --- a/Src/Setting.cs +++ b/Src/Setting.cs @@ -72,8 +72,8 @@ public string StringValueTrimmed /// public string StringValue { - get => GetValue().Trim('\"'); - set => SetValue(value.Trim('\"')); + get => Configuration.OutputRawStringValues ? GetValue() : GetValue().Trim('\"'); + set => SetValue(Configuration.OutputRawStringValues ? value : value.Trim('\"')); } /// From 7b2289d5378fd745dcdd720959c61e76bfa156a6 Mon Sep 17 00:00:00 2001 From: rboy1 <3846367+rboy1@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:56:34 -0400 Subject: [PATCH 3/4] Fix for handling comments --- Src/StockStringConverters.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/StockStringConverters.cs b/Src/StockStringConverters.cs index 1e18ac0..f622e95 100644 --- a/Src/StockStringConverters.cs +++ b/Src/StockStringConverters.cs @@ -324,10 +324,10 @@ public override object TryConvertFromString(string value, Type hint) internal sealed class StringStringConverter : TypeStringConverter { public override string ConvertToString(object value) - => value.ToString().Trim('\"'); + => Configuration.OutputRawStringValues ? value.ToString() : value.ToString().Trim('\"'); public override object TryConvertFromString(string value, Type hint) - => value.Trim('\"'); + => Configuration.OutputRawStringValues ? value : value.Trim('\"'); } internal sealed class UInt16StringConverter : TypeStringConverter From 9f850d5955ed5bc8e6fa91a712bfccb2ad747d43 Mon Sep 17 00:00:00 2001 From: Cem Dervis Date: Fri, 14 Nov 2025 17:28:04 +0100 Subject: [PATCH 4/4] Add test for inline comments in section names --- Tests/SimpleConfigTest.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Tests/SimpleConfigTest.cs b/Tests/SimpleConfigTest.cs index d1055b3..6e7e0fd 100644 --- a/Tests/SimpleConfigTest.cs +++ b/Tests/SimpleConfigTest.cs @@ -713,6 +713,32 @@ public void GetValueOrDefault() Assert.AreEqual(setting.GetValue(typeof(ulong)), 7654321); } + [Test] + public void TestCommentsInSectionNames() + { + var previous = Configuration.IgnoreInlineComments; + Configuration.IgnoreInlineComments = true; + + var cfg = new Configuration(); + cfg.Add("SomeSection1#NotAComment"); + cfg.Add(new Section("SomeSection2# also part of the section's name")); + + cfg["SomeSection1#NotAComment"].Add("Setting", 1); + cfg["SomeSection2# also part of the section's name"].Add("Setting", 2); + + TestWithFile(filename => + { + cfg.SaveToFile(filename); + + var parsedCfg = Configuration.LoadFromFile(filename); + + Assert.AreEqual("SomeSection1#NotAComment", parsedCfg[0].Name); + Assert.AreEqual("SomeSection2# also part of the section's name", parsedCfg[1].Name); + }); + + Configuration.IgnoreInlineComments = previous; + } + private static void TestWithFile(Action action) { string filename = Path.GetTempFileName();