From 0b8a36786729e57637a93f3271c26bf175bb67d6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 19 Dec 2019 20:45:27 +0000 Subject: [PATCH] Fix MiniYaml parsing of empty comments --- OpenRA.Game/MiniYaml.cs | 4 ++-- OpenRA.Test/OpenRA.Game/MiniYamlTest.cs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs index 2a58f0c199..dc3040e94d 100644 --- a/OpenRA.Game/MiniYaml.cs +++ b/OpenRA.Game/MiniYaml.cs @@ -225,7 +225,7 @@ namespace OpenRA if (commentStart < 0 && line[i] == '#' && (i == 0 || line[i - 1] != '\\')) { commentStart = i + 1; - if (commentStart < keyLength) + if (commentStart <= keyLength) keyLength = i - keyStart; else valueLength = i - valueStart; @@ -446,7 +446,7 @@ namespace OpenRA { var hasKey = !string.IsNullOrEmpty(key); var hasValue = !string.IsNullOrEmpty(Value); - var hasComment = !string.IsNullOrEmpty(comment); + var hasComment = comment != null; yield return (hasKey ? key + ":" : "") + (hasValue ? " " + Value.Replace("#", "\\#") : "") + (hasComment ? (hasKey || hasValue ? " " : "") + "#" + comment : ""); diff --git a/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs b/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs index e41ddde6e4..77d719c131 100644 --- a/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs +++ b/OpenRA.Test/OpenRA.Game/MiniYamlTest.cs @@ -246,10 +246,13 @@ TestB: { var yaml = @" # Top level comment node +# Parent: # comment without value # Indented comment node First: value containing a \# character Second: value # node with inline comment + Third: value # + Fourth: # ".Replace("\r\n", "\n"); var result = MiniYaml.FromString(yaml, discardCommentsAndWhitespace: false).WriteToString();