zserge / jsmn

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

Error parsing quotes on RHS #216

Closed donbowman closed 2 years ago

donbowman commented 2 years ago

If I have this json:

"{\"level\":\"info\",\"msg\":\"referer = \"\"\",\"time\":\"2022-01-18T17:40:13Z\"}"

it ends up w/ msg = referer and then "" = time.

This test will show:

+int test_quotes(void) {
+  const char * js = "{\"level\":\"info\",\"msg\":\"referer = \"\"\",\"time\":\"2022-01-18T17:40:13Z\"}";
+  int len = strlen(js);
+  check(parse(js, 8, 8, JSMN_OBJECT, 0, len, 3,
+              JSMN_STRING, "level", 1,
+              JSMN_STRING, "info", 0,
+              JSMN_STRING, "msg", 2,
+              JSMN_STRING, "referer = \"\"", 0,
+              JSMN_STRING, "time", 0,
+              JSMN_STRING, "2022-01-18T17:40:13Z", 0
+              ));
+  return 0;
+}
pt300 commented 2 years ago

Does this happen in strict mode? From what I see this is invalid JSON and the parsing should fail.

donbowman commented 2 years ago

so, mea culpa. i have an error here, missing a \ in the quotes.

I'm debugging through an issue with fluent-bit, i think the problem is upstream. After changing the test to have the extra \ it passes.