Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Stop parsing JSON after first finished construct. #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ EXTRA_DIST = \
fail31.json \
fail32.json \
fail33.json \
fail34.json \
fail3.json \
fail4.json \
fail5.json \
Expand Down
1 change: 1 addition & 0 deletions fail34.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{} garbage
1 change: 1 addition & 0 deletions unitester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static const char *filenames[] = {
"fail31.json",
"fail32.json",
"fail33.json",
"fail34.json",
"fail3.json",
"fail4.json", // extra comma
"fail5.json",
Expand Down
14 changes: 8 additions & 6 deletions univalue_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,16 @@ bool UniValue::read(const char *raw)
bool expectColon = false;
vector<UniValue*> stack;

string tokenVal;
unsigned int consumed;
enum jtokentype tok = JTOK_NONE;
enum jtokentype last_tok = JTOK_NONE;
while (1) {
do {
last_tok = tok;

string tokenVal;
unsigned int consumed;
tok = getJsonToken(tokenVal, consumed, raw);
if (tok == JTOK_NONE || tok == JTOK_ERR)
break;
return false;
raw += consumed;

switch (tok) {
Expand Down Expand Up @@ -377,9 +377,11 @@ bool UniValue::read(const char *raw)
default:
return false;
}
}
} while (!stack.empty ());

if (stack.size() != 0)
/* Check that nothing follows the initial construct (parsed above). */
tok = getJsonToken(tokenVal, consumed, raw);
if (tok != JTOK_NONE)
return false;

return true;
Expand Down