diff --git a/TODO.txt b/TODO.txt index 9a7b932..09d5c38 100644 --- a/TODO.txt +++ b/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 diff --git a/src/Json.c b/src/Json.c index be4d783..059a837 100644 --- a/src/Json.c +++ b/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));