Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected leniency with JSMN_STRICT defined #178

Open
mulle-nat opened this issue Dec 18, 2019 · 1 comment · May be fixed by #194 or #197
Open

Unexpected leniency with JSMN_STRICT defined #178

mulle-nat opened this issue Dec 18, 2019 · 1 comment · May be fixed by #194 or #197

Comments

@mulle-nat
Copy link

If I parse a JSON [ thanx ] with JSMN_STRICT defined, it doesn't really complain. Though thanx is not a keyword and needs to be quoted:

#define JSMN_STRICT
#include "jsmn.h"
#include <stdio.h>
#include <string.h>


static char  *json = "[\n"
"   thanx\n"
"]";


int main( void)
{
   jsmn_parser   p;
   jsmntok_t     t[128];
   int           r;
   int           i;

   jsmn_init( &p);
   r = jsmn_parse(&p, json, strlen( json), t, 128);
   if( r < 0)
   {
      fprintf( stderr, "Failed to parse JSON: %d\n", r);
      return 1;
   }
   for( i = 0; i < r; i++)
      printf( "%.*s (%d)\n", t[ i].end - t[ i].start, &json[ t[ i].start], t[i].type);
   return( 0);
}
@pt300
Copy link
Collaborator

pt300 commented Dec 18, 2019

That's due to how primitives are currently handled by JSMN. Only the first character is checked and if it matches t, f or n it is assumed those are respectively true, false or null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants