forked from lda/telodendria
Fix bugs in Json API.
This commit is contained in:
parent
31be432f7a
commit
7703405c70
2 changed files with 27 additions and 14 deletions
8
TODO.txt
8
TODO.txt
|
@ -13,9 +13,11 @@ Milestone: v0.2.0
|
|||
|
||||
[ ] Abstract /email/requestToken and /msidsn/requestToken
|
||||
|
||||
[ ] Json API
|
||||
[ ] Trailing commas should not be allowed in arrays and objects
|
||||
[ ] Fix empty arrays not parsing
|
||||
[x] Json API
|
||||
[x] Trailing commas should not be allowed in arrays and objects
|
||||
[x] Fix empty arrays not parsing
|
||||
[ ] Db API
|
||||
[ ] If object is in cache, but doesn't exist on disk, delete from cache
|
||||
[~] User login
|
||||
[x] User manipulation functions (so we don't use the DB directly)
|
||||
[x] Refresh tokens
|
||||
|
|
33
src/Json.c
33
src/Json.c
|
@ -945,6 +945,7 @@ static HashMap *
|
|||
JsonDecodeObject(JsonParserState * state)
|
||||
{
|
||||
HashMap *obj = HashMapCreate();
|
||||
int comma = 0;
|
||||
|
||||
if (!obj)
|
||||
{
|
||||
|
@ -986,19 +987,21 @@ JsonDecodeObject(JsonParserState * state)
|
|||
Free(key);
|
||||
|
||||
JsonTokenSeek(state);
|
||||
|
||||
if (JsonExpect(state, TOKEN_COMMA))
|
||||
{
|
||||
comma = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (JsonExpect(state, TOKEN_OBJECT_CLOSE))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (JsonExpect(state, TOKEN_COMMA))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
goto error;
|
||||
}
|
||||
else if (JsonExpect(state, TOKEN_OBJECT_CLOSE))
|
||||
else if (!comma && JsonExpect(state, TOKEN_OBJECT_CLOSE))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -1019,6 +1022,7 @@ JsonDecodeArray(JsonParserState * state)
|
|||
{
|
||||
Array *arr = ArrayCreate();
|
||||
size_t i;
|
||||
int comma = 0;
|
||||
|
||||
if (!arr)
|
||||
{
|
||||
|
@ -1030,6 +1034,12 @@ JsonDecodeArray(JsonParserState * state)
|
|||
JsonValue *value;
|
||||
|
||||
JsonTokenSeek(state);
|
||||
|
||||
if (!comma && JsonExpect(state, TOKEN_ARRAY_CLOSE))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
value = JsonDecodeValue(state);
|
||||
|
||||
if (!value)
|
||||
|
@ -1041,16 +1051,17 @@ JsonDecodeArray(JsonParserState * state)
|
|||
|
||||
JsonTokenSeek(state);
|
||||
|
||||
if (JsonExpect(state, TOKEN_COMMA))
|
||||
{
|
||||
comma = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (JsonExpect(state, TOKEN_ARRAY_CLOSE))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (JsonExpect(state, TOKEN_COMMA))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
goto error;
|
||||
} while (!JsonExpect(state, TOKEN_EOF));
|
||||
|
||||
|
|
Loading…
Reference in a new issue