Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EOF when parsing backslash quote #91

Open
xPaw opened this issue Jan 14, 2024 · 2 comments
Open

EOF when parsing backslash quote #91

xPaw opened this issue Jan 14, 2024 · 2 comments

Comments

@xPaw
Copy link
Member

xPaw commented Jan 14, 2024

"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
Copy link
Member Author

xPaw commented Jan 15, 2024

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.

@yaakov-h
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants