Fix MiniYaml parsing of empty comments
This commit is contained in:
@@ -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 : "");
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user