Skip to content

Commit

Permalink
Fix #382
Browse files Browse the repository at this point in the history
  • Loading branch information
joente committed May 14, 2024
1 parent 3cc777d commit 432854a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
16 changes: 16 additions & 0 deletions inc/ti/fn/fnjsonload.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions inc/ti/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -25,7 +25,7 @@
* "-rc0"
* ""
*/
#define TI_VERSION_PRE_RELEASE ""
#define TI_VERSION_PRE_RELEASE "-alpha0"

#define TI_MAINTAINER \
"Jeroen van der Heijden <jeroen@cesbit.com>"
Expand Down
13 changes: 13 additions & 0 deletions itest/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 432854a

Please sign in to comment.