Open alevesely opened 5 years ago
Oops, the fourth chunk above is obviously wrong. It should have been:
@@ -374,8 +377,20 @@
case ' ':
break;
case ':':
+ {
+#ifdef JSMN_STRICT
+ /* In strict mode members names are strings */
+ if (tokens)
+ {
+ jsmntok_t *key = parser->toknext >= 1? &tokens[parser->toknext - 1]: NULL;
+ if (key == NULL || key->type != JSMN_STRING)
+ return JSMN_ERROR_INVAL;
+ key->is_key = 1;
+ }
+#endif
parser->toksuper = parser->toknext - 1;
break;
+ }
case ',':
if (tokens != NULL && parser->toksuper != -1 &&
tokens[parser->toksuper].type != JSMN_ARRAY &&
The colon terminal ('
:
') seems to exist just for that, so it can be flagged while parsing. Doing it later requires careful counting (as in jsondump). Storingis_key
requires just one bit of the token type:The third hunk (
int
instead ofjsmntype_t
) is not related to this bug. It just avoids a compiler warning, which appeared also before changing the definition ofjsmntok_t
. See this question at stackoverflow.After the change, existing tests work fine. In addition, I tried this:
That way, jsondump aborts if it's not compiled with
JSMN_STRICT
. Otherwise it works. I should also check that no token is markedis_key
if it's not. Oh, well...I found an old bug #23. The change envisaged there would not be backward compatible. The code mentioned there is not available. The intent, however, is similar.