diff --git a/CHANGELOG.md b/CHANGELOG.md index cc681360..926149b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v1.6.3 + +* Honor key restrictions with JSON load function, issue #382. + # v1.6.2 * Fixed loading JSON strings with `json_load()` function, issue #381. diff --git a/inc/ti/fn/fnjsonload.h b/inc/ti/fn/fnjsonload.h index 10d5b267..db01ea6d 100644 --- a/inc/ti/fn/fnjsonload.h +++ b/inc/ti/fn/fnjsonload.h @@ -121,6 +121,22 @@ static int jload__start_map(void * ctx) static int jload__map_key(void * ctx, const unsigned char * s, size_t n) { jload__convert_t * c = (jload__convert_t *) ctx; + + if (!strx_is_utf8n((const char *) s, n)) + { + ex_set(c->e, EX_VALUE_ERROR, + "properties must have valid UTF-8 encoding"); + return 0; /* failed */ + } + + if (ti_is_reserved_key_strn((const char *) s, n)) + { + ex_set(c->e, EX_VALUE_ERROR, + "property `%c` is reserved"DOC_PROPERTIES, + *s); + return 0; /* failed */ + } + jload__key = ti_str_create((const char *) s, n); if (!jload__key) { diff --git a/inc/ti/version.h b/inc/ti/version.h index 4141e00c..fa97124c 100644 --- a/inc/ti/version.h +++ b/inc/ti/version.h @@ -6,7 +6,7 @@ #define TI_VERSION_MAJOR 1 #define TI_VERSION_MINOR 6 -#define TI_VERSION_PATCH 2 +#define TI_VERSION_PATCH 3 /* The syntax version is used to test compatibility with functions * using the `ti_nodes_check_syntax()` function */ @@ -25,7 +25,7 @@ * "-rc0" * "" */ -#define TI_VERSION_PRE_RELEASE "" +#define TI_VERSION_PRE_RELEASE "-alpha0" #define TI_MAINTAINER \ "Jeroen van der Heijden " diff --git a/itest/test_advanced.py b/itest/test_advanced.py index 886bd5cb..f7d8f6f5 100755 --- a/itest/test_advanced.py +++ b/itest/test_advanced.py @@ -2600,6 +2600,19 @@ async def test_json_load_i(self, client): json_load('[{"a": [{"b": [1, 1], "c": [3, ..]}]}]'); """) + # bug #382 + with self.assertRaisesRegex( + ValueError, + r'property `\#` is reserved'): + await client.query("""//ti + json_load('[{"#": 123}]'); + """) + + self.assertTrue(await client.query("""//ti + x = json_load('[[]]'); + is_tuple(x.first()); + """)) + if __name__ == '__main__': run_test(TestAdvanced())