zserge / jsmn

Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket
MIT License
3.65k stars 778 forks source link

add more strict checking #119

Closed lunatikub closed 5 years ago

lunatikub commented 7 years ago

add more strict checking

lunatikub commented 6 years ago

@chlunde Fixed !

lunatikub commented 6 years ago

Any news ?

edsiper commented 6 years ago

@lunatikub

I am using your patch in our project here:

https://github.com/fluent/fluent-bit/tree/master/lib/jsmn

I've found that when running in strict mode and tokens is NULL (because I want only to validate the string and not to populate results), the validation fails, a simple JSON map input like this helps to reproduce the problem:

{"key": "some value"}

e.g:

    ret = jsmn_parse(&parser, json, len, NULL, 0);

any hints are appreciated.

lunatikub commented 6 years ago

Hi @edsiper,

Thanks for highlighting this important point in my patch:

The strict mode needs the array of tokens to validate a JSON: in the case of a string token, its needs to know the type of the parent to deduce the type of the next token by the function 'jsmn_string_next_tok'.

For instance, if a string is being parsed and the parent is an 'array', the next type after a comma must be a 'value'.

With this point in mind, I will modify the patch so that passing a NULL 'tokens' array will not be accepted by the function 'jsmn_parse'.

It will look like: `#ifdef JSMN_STRICT assert(tokens != NULL);

endif`

Warm regards, Thomas,

edsiper commented 6 years ago

@lunatikub thanks for the detailed info, that makes a lot of sense, I will go ahead and deprecate the usage of jsmn_parse() in that mode.

btw, have you consider to maintain a fork of this project since it low activity from a maintainer perspective ?

pt300 commented 5 years ago

More changes ahead.