Bugfix: incorrect logic in the parsing of comments fails to detect EOF properly

This commit is contained in:
Zahary Karadjov 2020-10-09 19:32:25 +03:00
parent 1dccd4b2ef
commit 3b0c9eafa4
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
2 changed files with 17 additions and 5 deletions

View File

@ -225,19 +225,21 @@ proc skipWhitespace(lexer: var JsonLexer) =
checkForUnexpectedEof()
case lexer.stream.peek()
of '/':
advance lexer.stream
while true:
advance lexer.stream
if not lexer.stream.readable: return
case lexer.stream.peek()
of '\r':
handleCR()
break
of '\n':
lexer.handleLF()
break
else:
discard
advance lexer.stream
of '*':
advance lexer.stream
while true:
advance lexer.stream
if not lexer.stream.readable: return
case lexer.stream.peek()
of '\r':
@ -249,9 +251,9 @@ proc skipWhitespace(lexer: var JsonLexer) =
checkForUnexpectedEof()
if lexer.stream.peek() == '/':
advance lexer.stream
return
break
else:
discard
advance lexer.stream
else:
error errCommentExpected
of ' ', '\t':

View File

@ -261,3 +261,13 @@ suite "toJson tests":
test "Holders of JsonNode":
testJsonHolders HasJsonNode
test "Json with comments":
const jsonContent = staticRead "./cases/comments.json"
try:
let decoded = Json.decode(jsonContent, JsonNode)
check decoded["tasks"][0]["label"] == newJString("nim-beacon-chain build")
except SerializationError as err:
checkpoint err.formatMsg("./cases/comments.json")
fail