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

Support testing UniValue with JSON Parsing Test Suite #1

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
29 changes: 17 additions & 12 deletions src/univalue/lib/univalue_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ enum jtokentype getJsonToken(string& tokenVal, unsigned int& consumed,
string valStr;
JSONUTF8StringFilter writer(valStr);

while (*raw) {
while (true) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while

if ((unsigned char)*raw < 0x20)
return JTOK_ERR;

Expand Down Expand Up @@ -371,9 +371,6 @@ bool UniValue::read(const char *raw)
case JTOK_KW_NULL:
case JTOK_KW_TRUE:
case JTOK_KW_FALSE: {
if (!stack.size())
return false;

UniValue tmpVal;
switch (tok) {
case JTOK_KW_NULL:
Expand All @@ -388,6 +385,11 @@ bool UniValue::read(const char *raw)
default: /* impossible */ break;
}

if (!stack.size()) {
*this = tmpVal;
break;
}

UniValue *top = stack.back();
top->values.push_back(tmpVal);

Expand All @@ -396,10 +398,12 @@ bool UniValue::read(const char *raw)
}

case JTOK_NUMBER: {
if (!stack.size())
return false;

UniValue tmpVal(VNUM, tokenVal);
if (!stack.size()) {
*this = tmpVal;
break;
}

UniValue *top = stack.back();
top->values.push_back(tmpVal);

Expand All @@ -408,17 +412,18 @@ bool UniValue::read(const char *raw)
}

case JTOK_STRING: {
if (!stack.size())
return false;

UniValue *top = stack.back();

if (expect(OBJ_NAME)) {
UniValue *top = stack.back();
top->keys.push_back(tokenVal);
clearExpect(OBJ_NAME);
setExpect(COLON);
} else {
UniValue tmpVal(VSTR, tokenVal);
if (!stack.size()) {
*this = tmpVal;
break;
}
UniValue *top = stack.back();
top->values.push_back(tmpVal);
}

Expand Down