An additional closing curly brace is missed by the parser. If a file contains a closing curly brace too many, parsing is ended prematurely.
Multiple things could happen in case of an additional closing curly brace:
- The amount of curly braces in the document can be counted and the opening ones should match the closing ones
- The amount of bytes read could be returned for verification (compare with file size)
- A warning/error can be given if there are characters found after the curly brace
The current silent ending of the read process gives unintended behaviour.
Example Json:
{
"Product A":
{
"address": [ 84 ],
"filename": "filea.bx",
"version": "v01.04.F1.dev",
"enabled": true,
"hasCan": true,
"boardaddresses" : [ 1 , 2 ]
}
},
"Product B":
{
"address": [ 85 ],
"filename": "fileb.bx",
"version": "01.02.06",
"enabled": false,
"hasCan": true
}
}
Basically anything that can parse as a valid token will be accepted (and ignored) at the end of an otherwise valid string. Our solution was to add the following code to the main parse routine, just before check for features_.strictRoot_ :
if ( current_ != end_ )
{
token.type_ = tokenError;
token.start_ = current_;
token.end_ = endDoc;
addError( "Root node successfully parsed but extra data was found and not parsed.",
token );
return false;
}
That's not a bug, but it's prevented by using
strictMode
at: https://github.com/open-source-parsers/jsoncpp/