jsmn
jsmn copied to clipboard
Multiple root elements
Wouldn't it make sense to return an error if multiple root elements are found and JSMN_STRICT is defined? e.g. "{}{}" is not valid JSON and jsmn could/should return an error. This code would do the trick:
}
token->end = parser->pos + 1;
parser->toksuper = token->parent;
+ if (token->parent == -1) {
+#ifdef JSMN_STRICT
+ // ensure that no junk data is present
+ for (; js[parser->pos+1] != '\0'; parser->pos++) {
+ char c;
+ c = js[parser->pos+1];
+ if (!isspace(c)) {
+ return JSMN_ERROR_JUNK;
+ }
+ }
+#endif
+ break;
+ }
break;
}
if (token->parent == -1) {
(Note: I hesitate to create a pull request, as I never used HG as well as Bitbucket so far. But if you're willing to merge this and you want to have a pull request, I'll create one of course)
- Bitbucket: https://bitbucket.org/zserge/jsmn/issue/49
- Originally reported by: jose maria
- Originally created at: 2015-06-05T10:47:14.787