Closed 13xforever closed 3 years ago
Thanks for the bug report! This is probably because of the escaped quotes in the string - the SplitWithQuotes
method doesn't have any support for escaped quotes. The method already loops through each character in the line, so adding support for an escape character shouldn't be too hard. It's a good chance for me to write some unit tests for it as well.
Some basic test cases for my own reference
var testCases = new Dictionary<string, string[]>
{
["Simple"] = new[] { "Simple" },
["No Quotes"] = new[] { "No", "Quotes" },
[@"""With"" ""Quotes"""] = new[] { "With", "Quotes" },
[@"""Empty"" """""] = new[] { "Empty", "" },
[@"""With"" ""\""Escaped\"" Quotes"""] = new[] { "With", @"""Escaped"" Quotes" },
[@"""Json"" ""{ \""Key\"": \""Value\"" }"""] = new [] {"Json", @"{ ""Key"": ""Value"" }"}
};
foreach (var (input, expected) in testCases)
{
$"TEST: {input}".Dump();
try
{
var actual = SplitWithQuotes(input);
if (!actual.SequenceEqual(expected)) $"Test failed. Expected <{String.Join(", ", expected)}>, got <{String.Join(", ", actual)}>".Dump();
else "Test passed.".Dump();
}
catch (Exception ex)
{
$"Test failed. Exception: {ex.Message}".Dump();
}
"".Dump();
}
Current output:
TEST: Simple
Test passed.
TEST: No Quotes
Test passed.
TEST: "With" "Quotes"
Test passed.
TEST: "Empty" ""
Test passed.
TEST: "With" "\"Escaped\" Quotes"
Test failed. Exception: Index and length must refer to a location within the string. (Parameter 'length')
TEST: "Json" "{ \"Key\": \"Value\" }"
Test failed. Exception: Index and length must refer to a location within the string. (Parameter 'length')
The easiest way to reproduce is to try and parse
steam\userdata\<user_id>\7\remote\sharedconfig.vdf
, which has such property atUserLocalConfigStore
>Software
>Valve
>Steam
>FriendsUI
>FriendsUIJSON
.Here's an excerpt: