webmcp

changeset 153:c8c91216255f

Correct treatment of top-level null values in JSON parser
author jbe
date Thu Jul 31 01:21:33 2014 +0200 (2014-07-31)
parents 7b5c13fdc2ec
children c8669dde9ce2
files libraries/json/json.c
line diff
     1.1 --- a/libraries/json/json.c	Thu Jul 31 01:02:46 2014 +0200
     1.2 +++ b/libraries/json/json.c	Thu Jul 31 01:21:33 2014 +0200
     1.3 @@ -381,8 +381,16 @@
     1.4    } else if (!strncmp(str+pos, "null", 4)) {
     1.5      // consume 4 input characters for "null":
     1.6      pos += 4;
     1.7 -    // put special null-marker onto stack:
     1.8 -    lua_pushvalue(L, json_import_nullmark_idx);
     1.9 +    // different behavor for top-level and sub-levels:
    1.10 +    if (level) {
    1.11 +      // if sub-level,
    1.12 +      // push special null-marker onto stack:
    1.13 +      lua_pushvalue(L, json_import_nullmark_idx);
    1.14 +    } else {
    1.15 +      // if top-level,
    1.16 +      // push nil onto stack:
    1.17 +      lua_pushnil(L);
    1.18 +    }
    1.19    } else {
    1.20      // all other cases are a syntax error:
    1.21      goto json_import_syntax_error;

Impressum / About Us