Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/_jsonnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static int handle_native_callbacks(struct JsonnetVm *vm, PyObject *native_callba
/* Check the params are all strings */
num_params = PyTuple_Size(params);
for (i = 0; i < num_params ; ++i) {
PyObject *param = PyTuple_GetItem(params, 0);
PyObject *param = PyTuple_GetItem(params, i);
if (!PyUnicode_Check(param)) {
PyErr_SetString(PyExc_TypeError, "native callback param must be string");
goto bad;
Expand Down
12 changes: 11 additions & 1 deletion python/_jsonnet_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,17 @@ def test_double_import(self):
import_callback=import_callback_encode,
native_callbacks=native_callbacks,
)
self.assertEqual(json_str, "84\n")
def test_native_callback_param_type_validation(self):
def dummy_cb(*args):
return None

# Verify that non-string parameters beyond the first index are rejected with TypeError
with self.assertRaises(TypeError):
_jsonnet.evaluate_snippet(
self.test_filename,
"null",
native_callbacks={"invalid_param": (("valid", 123), dummy_cb)},
)

if __name__ == '__main__':
unittest.main()