Skip to content

Commit

Permalink
Fixed VdfTextReader treating slashes in quoted values as comments
Browse files Browse the repository at this point in the history
- Resolves #27.
- Also added a test so it doesn't break again.
  • Loading branch information
shravan2x committed Jun 20, 2020
1 parent c2aa841 commit c27ca7a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gameloop.Vdf/VdfTextReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override bool ReadToken()
continue;
}
}
else if (_tokenSize == 0 && curChar == VdfStructure.Comment && _charBuffer[_charPos + 1] == VdfStructure.Comment)
else if (!_isQuoted && _tokenSize == 0 && curChar == VdfStructure.Comment && _charBuffer[_charPos + 1] == VdfStructure.Comment)
{
_isComment = true;
_charPos += 2;
Expand Down
21 changes: 20 additions & 1 deletion Tests/VdfConvertFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void EmptyStringThrowsException()
[Fact]
public void CommentsDeserializeCorrectly()
{
string vdf = @"
const string vdf = @"
// Comment type A (at the start of the file)
""root""
{
Expand Down Expand Up @@ -44,5 +44,24 @@ public void CommentsDeserializeCorrectly()

Assert.True(VToken.DeepEquals(result, expected));
}

[Fact]
public void DoubleSlashInValueDeserializesCorrectly()
{
const string vdf = @"
""root""
{
""key1"" ""//""
}
";
VProperty result = VdfConvert.Deserialize(vdf);

VProperty expected = new VProperty("root", new VObject
{
new VProperty("key1", new VValue("//")),
});

Assert.True(VToken.DeepEquals(result, expected));
}
}
}

0 comments on commit c27ca7a

Please sign in to comment.