diff --git a/python/_jsonnet.c b/python/_jsonnet.c index 00cace76..b9f7b93d 100644 --- a/python/_jsonnet.c +++ b/python/_jsonnet.c @@ -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; diff --git a/python/_jsonnet_test.py b/python/_jsonnet_test.py index ddb09c74..c948c167 100644 --- a/python/_jsonnet_test.py +++ b/python/_jsonnet_test.py @@ -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()