ValveKeyValue icon indicating copy to clipboard operation
ValveKeyValue copied to clipboard

EOF when parsing backslash quote

Open xPaw opened this issue 1 year ago • 2 comments

"test case"
{
	"key"		"some value\""
	"foo"		"bar"
}

See https://github.com/ValveResourceFormat/ValveKeyValue/tree/eof-unescape-bug

This throws:

ValveKeyValue.KeyValueException : Found end of file while trying to read token.
  ----> System.IO.EndOfStreamException : Attempted to read past the end of the stream.

  Stack Trace: 
    KV1TextReader.ReadObject() line 50
KVSerializer.Deserialize(Stream stream, KVSerializerOptions options) line 44
EscapedQuoteNoEscapeTestCase.SetUp() line 21
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
--EndOfStreamException
KV1TokenReader.Next() line 175
KV1TokenReader.ReadUntil(Char[] terminators) line 221
KV1TokenReader.ReadQuotedStringRaw() line 316
KV1TokenReader.ReadStringRaw() line 305
KV1TokenReader.ReadString() line 81
KV1TokenReader.ReadNextToken() line 64
KV1TextReader.ReadObject() line 42

\" causes it to trip up, it works with HasEscapeSequences: true. It's probably fine for this not to parse correctly, but I would at least expect the exception to be somewhat better than EOF

xPaw avatar Jan 14 '24 20:01 xPaw

It's likely due to the extra quote, which misaligns all the keys/values. The only real improvement I can think of is to improve the exception message (add line number, print last key), but it will end up printing the very last line, and not the actual one where the issue happened.

xPaw avatar Jan 15 '24 09:01 xPaw

The best solution I can think of may be tricky but it would be to check this condition and flag the first string that contains a newline (or the one before it?) as suspicious

yaakov-h avatar Jan 15 '24 09:01 yaakov-h