Skip to content

Commit

Permalink
Fix #381
Browse files Browse the repository at this point in the history
  • Loading branch information
joente committed May 13, 2024
1 parent 35248fa commit 0bd7db3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
30 changes: 11 additions & 19 deletions inc/ti/fn/fnjsonload.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,22 @@ static int jload__start_array(void * ctx)
jload__convert_t * c = (jload__convert_t *) ctx;
ti_val_t * val;

if (++c->deep >= YAJL_MAX_DEPTH)
{
ex_set(c->e, EX_OPERATION, "JSON max depth exceeded");
return 0; /* error */
}

val = (ti_val_t *) ti_varr_create(7);
if (!val)
{
ex_set_mem(c->e);
return 0; /* failed */
}

if (c->callbacks[c->deep](c->parents[c->deep], val, c->e))
return 0; /* failed */

if (++c->deep >= YAJL_MAX_DEPTH)
{
ex_set(c->e, EX_OPERATION, "JSON max depth exceeded");
return 0; /* error */
}

c->parents[c->deep] = val;
c->callbacks[c->deep] = (jload__set_cb) jload__array_cb;
return 1; /* success */
Expand All @@ -163,8 +166,8 @@ static int jload__start_array(void * ctx)
static int jload__end_array(void * ctx)
{
jload__convert_t * c = (jload__convert_t *) ctx;
ti_val_t * val = c->parents[c->deep--];
return 0 == c->callbacks[c->deep](c->parents[c->deep], val, c->e);
--c->deep;
return 1; /* success */
}

static yajl_callbacks jload__callbacks = {
Expand Down Expand Up @@ -233,17 +236,6 @@ static int do__f_json_load(ti_query_t * query, cleri_node_t * nd, ex_t * e)
else
ex_set_mem(e);
}
while (ctx.deep)
{
/*
* Each but the last parent is a value type. If an array, then the
* value exists but is not appended to another type. Thus, we need
* to clear the array's in the list.
*/
ti_val_t * val = ctx.parents[ctx.deep--];
if (val && ti_val_is_array(val))
ti_val_unsafe_drop(val);
}

ti_val_drop(ctx.out);
free(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 1
#define TI_VERSION_PATCH 2

/* 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 <[email protected]>"
Expand Down
33 changes: 23 additions & 10 deletions itest/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def test_qcache_recursion(self, client):
self.assertEqual(len(res), 532)

async def test_extend_restrict(self, client):
res = await client.query(r"""//ti
_res = await client.query(r"""//ti
set_type('A', {arr: '[str]'});
""")
with self.assertRaisesRegex(
Expand Down Expand Up @@ -1174,7 +1174,7 @@ async def test_mod_del_in_use(self, client):
OperationError,
r'cannot change type `X` while one of the '
r'instances is in use'):
res = await client.query('''
_res = await client.query('''
set_type('X', {
a: 'int',
b: 'int',
Expand Down Expand Up @@ -1666,7 +1666,7 @@ async def test_ren_after_mod(self, client):
self.assertNotIn('m', methods)
self.assertEqual(len(methods), 1)

async def test_mod_with_restriction(self, client):
async def test_mod_with_restric_199(self, client):
# bug #199
res = await client.query(r"""//ti
set_type('Test', {i: 'pint'});
Expand All @@ -1675,7 +1675,7 @@ async def test_mod_with_restriction(self, client):
""")
self.assertEqual(res, {"i": 0})

async def test_mod_with_restriction(self, client):
async def test_mod_with_restrict_200(self, client):
# bug #200
with self.assertRaisesRegex(
OperationError,
Expand Down Expand Up @@ -1829,7 +1829,7 @@ async def test_future_to_type(self, client):
};
""")

async def test_in_use_on_dict(self, client):
async def test_in_use_on_dict_242(self, client):
# bug #242
await client.query(".set('non name key', nil);")
with self.assertRaisesRegex(
Expand All @@ -1844,7 +1844,7 @@ async def test_in_use_on_dict(self, client):
})
""")

async def test_in_use_on_dict(self, client):
async def test_in_use_on_dict_243(self, client):
# bug #243
res = await client.query(r"""//ti
new_type('A');
Expand Down Expand Up @@ -1887,14 +1887,14 @@ async def test_replace_rev_large(self, client):
self.assertEqual(s, res)

async def test_loop_gc(self, client):
res = await client.query(r"""//ti
_res = await client.query(r"""//ti
for (x in range(10)) {
x = {};
x.me = x;
};
""")
# bug #259
res = await client.query(r"""//ti
_res = await client.query(r"""//ti
range(10).sort(|a, b| {
a = {}; // overwrite the closure argument
a.me = a; // create a self reference
Expand Down Expand Up @@ -2140,9 +2140,9 @@ async def test_no_declaration_after_flags(self, client):
set_type("A", {x: "&"});
""")

async def test_(self, client):
async def test_309(self, client):
# bug #309
res = await client.query("""//ti
_res = await client.query("""//ti
new_type('A');
new_type('C');
set_type('A',{
Expand Down Expand Up @@ -2587,6 +2587,19 @@ async def test_utf8_range(self, client):
""")
self.assertEqual(res, {"u": "D"})

async def test_json_load_i(self, client):
# bug #381
await client.query("""//ti
json_load('{"a": [{"b": 123}]}');
""")

with self.assertRaisesRegex(
ValueError,
r'lexical error: invalid char in json text'):
await client.query("""//ti
json_load('[{"a": [{"b": [1, 1], "c": [3, ..]}]}]');
""")


if __name__ == '__main__':
run_test(TestAdvanced())

0 comments on commit 0bd7db3

Please sign in to comment.