aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--lua_cjson.c12
-rw-r--r--strbuf.c4
-rwxr-xr-xtests/test.lua8
4 files changed, 15 insertions, 14 deletions
diff --git a/README.md b/README.md
index 233a094..08398cb 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,7 @@ Table of Contents
18 * [encode_skip_unsupported_value_types](#encode_skip_unsupported_value_types) 18 * [encode_skip_unsupported_value_types](#encode_skip_unsupported_value_types)
19 * [encode_indent](#encode_indent) 19 * [encode_indent](#encode_indent)
20 * [decode_array_with_array_mt](#decode_array_with_array_mt) 20 * [decode_array_with_array_mt](#decode_array_with_array_mt)
21 * [decode_allow_comment](#decode_allow_comment)
21 22
22Description 23Description
23=========== 24===========
@@ -263,9 +264,9 @@ cjson.encode(t) -- {"my_array":[]} properly re-encoded as an array
263 264
264[Back to TOC](#table-of-contents) 265[Back to TOC](#table-of-contents)
265 266
266decode_allow_comments 267decode_allow_comment
267-------------------------- 268--------------------------
268**syntax:** `cjson.decode_allow_comments(enabled)` 269**syntax:** `cjson.decode_allow_comment(enabled)`
269 270
270**default:** false 271**default:** false
271 272
diff --git a/lua_cjson.c b/lua_cjson.c
index de77f26..0ee9f7d 100644
--- a/lua_cjson.c
+++ b/lua_cjson.c
@@ -179,7 +179,7 @@ typedef struct {
179 int decode_invalid_numbers; 179 int decode_invalid_numbers;
180 int decode_max_depth; 180 int decode_max_depth;
181 int decode_array_with_array_mt; 181 int decode_array_with_array_mt;
182 int decode_allow_comments; 182 int decode_allow_comment;
183 int encode_skip_unsupported_value_types; 183 int encode_skip_unsupported_value_types;
184} json_config_t; 184} json_config_t;
185 185
@@ -386,11 +386,11 @@ static int json_cfg_decode_array_with_array_mt(lua_State *l)
386} 386}
387 387
388/* Configures whether decoder allows comments */ 388/* Configures whether decoder allows comments */
389static int json_cfg_decode_allow_comments(lua_State *l) 389static int json_cfg_decode_allow_comment(lua_State *l)
390{ 390{
391 json_config_t *cfg = json_arg_init(l, 1); 391 json_config_t *cfg = json_arg_init(l, 1);
392 392
393 json_enum_option(l, 1, &cfg->decode_allow_comments, NULL, 1); 393 json_enum_option(l, 1, &cfg->decode_allow_comment, NULL, 1);
394 394
395 return 1; 395 return 1;
396} 396}
@@ -527,7 +527,7 @@ static void json_create_config(lua_State *l)
527 cfg->encode_number_precision = DEFAULT_ENCODE_NUMBER_PRECISION; 527 cfg->encode_number_precision = DEFAULT_ENCODE_NUMBER_PRECISION;
528 cfg->encode_empty_table_as_object = DEFAULT_ENCODE_EMPTY_TABLE_AS_OBJECT; 528 cfg->encode_empty_table_as_object = DEFAULT_ENCODE_EMPTY_TABLE_AS_OBJECT;
529 cfg->decode_array_with_array_mt = DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT; 529 cfg->decode_array_with_array_mt = DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT;
530 cfg->decode_allow_comments = DEFAULT_DECODE_ALLOW_COMMENTS; 530 cfg->decode_allow_comment = DEFAULT_DECODE_ALLOW_COMMENTS;
531 cfg->encode_escape_forward_slash = DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH; 531 cfg->encode_escape_forward_slash = DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH;
532 cfg->encode_skip_unsupported_value_types = DEFAULT_ENCODE_SKIP_UNSUPPORTED_VALUE_TYPES; 532 cfg->encode_skip_unsupported_value_types = DEFAULT_ENCODE_SKIP_UNSUPPORTED_VALUE_TYPES;
533 cfg->encode_indent = DEFAULT_ENCODE_INDENT; 533 cfg->encode_indent = DEFAULT_ENCODE_INDENT;
@@ -1302,7 +1302,7 @@ static void json_next_token(json_parse_t *json, json_token_t *token)
1302 json->ptr++; 1302 json->ptr++;
1303 } 1303 }
1304 1304
1305 if (!json->cfg->decode_allow_comments) 1305 if (!json->cfg->decode_allow_comment)
1306 break; 1306 break;
1307 1307
1308 /* Eat comments. */ 1308 /* Eat comments. */
@@ -1671,7 +1671,7 @@ static int lua_cjson_new(lua_State *l)
1671 { "decode", json_decode }, 1671 { "decode", json_decode },
1672 { "encode_empty_table_as_object", json_cfg_encode_empty_table_as_object }, 1672 { "encode_empty_table_as_object", json_cfg_encode_empty_table_as_object },
1673 { "decode_array_with_array_mt", json_cfg_decode_array_with_array_mt }, 1673 { "decode_array_with_array_mt", json_cfg_decode_array_with_array_mt },
1674 { "decode_allow_comments", json_cfg_decode_allow_comments }, 1674 { "decode_allow_comment", json_cfg_decode_allow_comment },
1675 { "encode_sparse_array", json_cfg_encode_sparse_array }, 1675 { "encode_sparse_array", json_cfg_encode_sparse_array },
1676 { "encode_max_depth", json_cfg_encode_max_depth }, 1676 { "encode_max_depth", json_cfg_encode_max_depth },
1677 { "decode_max_depth", json_cfg_decode_max_depth }, 1677 { "decode_max_depth", json_cfg_decode_max_depth },
diff --git a/strbuf.c b/strbuf.c
index 704f702..8aa0747 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -86,7 +86,7 @@ static inline void debug_stats(strbuf_t *s)
86{ 86{
87 if (s->debug) { 87 if (s->debug) {
88 fprintf(stderr, "strbuf(%p) reallocs: %d, length: %zd, size: %zd\n", 88 fprintf(stderr, "strbuf(%p) reallocs: %d, length: %zd, size: %zd\n",
89 s, s->reallocs, s->length, s->size); 89 (void *) s, s->reallocs, s->length, s->size);
90 } 90 }
91} 91}
92 92
@@ -165,7 +165,7 @@ void strbuf_resize(strbuf_t *s, size_t len)
165 165
166 if (s->debug > 1) { 166 if (s->debug > 1) {
167 fprintf(stderr, "strbuf(%p) resize: %zd => %zd\n", 167 fprintf(stderr, "strbuf(%p) resize: %zd => %zd\n",
168 s, s->size, newsize); 168 (void *) s, s->size, newsize);
169 } 169 }
170 170
171 s->size = newsize; 171 s->size = newsize;
diff --git a/tests/test.lua b/tests/test.lua
index 068a9f0..270f63a 100755
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -334,8 +334,8 @@ local cjson_tests = {
334 false, { "Expected value but found invalid unicode escape code at character 2" } }, 334 false, { "Expected value but found invalid unicode escape code at character 2" } },
335 335
336 -- Test comments 336 -- Test comments
337 { 'Set decode_allow_comments(true)', 337 { 'Set decode_allow_comment(true)',
338 json.decode_allow_comments, { true }, true, { true } }, 338 json.decode_allow_comment, { true }, true, { true } },
339 { "Decode single-line comment", 339 { "Decode single-line comment",
340 json.decode, { '{//comment\n}' }, true, { {} } }, 340 json.decode, { '{//comment\n}' }, true, { {} } },
341 { "Decode single-line comment with windows newline", 341 { "Decode single-line comment with windows newline",
@@ -356,8 +356,8 @@ local cjson_tests = {
356 { "Decode comment inside number [throw error]", 356 { "Decode comment inside number [throw error]",
357 json.decode, { '{"a":1/*x*/0}' }, 357 json.decode, { '{"a":1/*x*/0}' },
358 false, { "Expected comma or object end but found T_INTEGER at character 12" } }, 358 false, { "Expected comma or object end but found T_INTEGER at character 12" } },
359 { 'Set decode_allow_comments(false)', 359 { 'Set decode_allow_comment(false)',
360 json.decode_allow_comments, { false }, true, { false } }, 360 json.decode_allow_comment, { false }, true, { false } },
361 361
362 -- Test indenting 362 -- Test indenting
363 { 'Set encode_indent(" ")', 363 { 'Set encode_indent(" ")',