From 82f378a63dd56c2ffb0779957da9ea031937c63d Mon Sep 17 00:00:00 2001 From: "Dominick C. Pastore" Date: Mon, 25 May 2020 16:28:05 -0400 Subject: [PATCH] Enable partial array test for non-strict mode --- jsmn.h | 7 ++++++- test/tests.c | 2 -- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/jsmn.h b/jsmn.h index 097c5625..f4187561 100644 --- a/jsmn.h +++ b/jsmn.h @@ -111,8 +111,10 @@ typedef struct jsmn_parser { unsigned int toknext; /* next token to allocate */ int toksuper; /* superior token node, e.g. parent object or array */ int state; /* parser state, from jsmnstate_t */ - unsigned int depth; /* Nesting depth of arrays and objects (used only when + unsigned int depth; /* nesting depth of arrays and objects (used only when * tokens is NULL) */ + int tokbefore; /* token immediately preceding the first token in the + current JSON object */ } jsmn_parser; /** @@ -406,6 +408,7 @@ JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len, } #endif if (parser->toksuper == -1) { + parser->tokbefore = parser->toknext - 1; return count; } else { parser->state = (tokens[parser->toksuper].type == JSMN_ARRAY) ? @@ -426,6 +429,7 @@ JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len, } } if (parser->toksuper == -1) { + parser->tokbefore = parser->toknext - 1; return count; } else if (parser->state & 0x1) { return JSMN_ERROR_INVAL; @@ -503,6 +507,7 @@ JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len, } } if (parser->toksuper == -1) { + parser->tokbefore = parser->toknext - 1; return count; #ifdef JSMN_STRICT } else if (parser->state & 0x3) { diff --git a/test/tests.c b/test/tests.c index 51d45880..cddd076c 100644 --- a/test/tests.c +++ b/test/tests.c @@ -125,7 +125,6 @@ int test_partial_string(void) { } int test_partial_array(void) { -#ifdef JSMN_STRICT int r; unsigned long i; jsmn_parser p; @@ -144,7 +143,6 @@ int test_partial_array(void) { check(r == JSMN_ERROR_PART); } } -#endif return 0; }