diff --git a/Json.cpp b/Json.cpp index 5831bc2d..c98e70f1 100644 --- a/Json.cpp +++ b/Json.cpp @@ -241,7 +241,8 @@ JsonItem *Json::parseJsonStringIntoJsonItems ( char *json , long niceness ) { // . otherwise, it was field value, so index it // . TODO: later make field names compounded to // better represent nesting? - else { + // . added 'else if (NAME){' fix for json=\"too small\" + else if ( NAME ) { // make a new one in safebuf. our // parent will be the array type item. ji = addNewItem(); @@ -264,6 +265,11 @@ JsonItem *Json::parseJsonStringIntoJsonItems ( char *json , long niceness ) { // ok, this one is done ji = NULL; } + else { + log("json: fieldless name in json"); + g_errno = EBADJSONPARSER; + return false; + } // skip over the string size = 0; p = x; diff --git a/main.cpp b/main.cpp index 04ed8d72..da1a59c1 100644 --- a/main.cpp +++ b/main.cpp @@ -1236,10 +1236,11 @@ int main2 ( int argc , char *argv[] ) { } /* - test json parser error with bad json + // test json parser error with bad json Json jp; char xxx[1024]; - sprintf(xxx,"\"categories\":[\"shop\""); + //sprintf(xxx,"\"categories\":[\"shop\""); + sprintf(xxx,"\"too small\""); jp.parseJsonStringIntoJsonItems(xxx,0); JsonItem *ji = jp.getFirstItem(); for ( ; ji ; ji = ji->m_next ) {