summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-03-16 13:17:47 +0000
committerMichael Williamson <mike@zwobble.org>2023-03-16 13:30:29 +0000
commit7a2648dfe150f532d1690fa8fbaf588789afaa84 (patch)
treed299bf6fc98e86b841c2cce769b996f5abe1ab3e
parent125196c17a00311ce132148369982795e2d229ce (diff)
Handle null bytes in object keys
-rw-r--r--jq.pyx2
-rw-r--r--tests/jq_tests.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/jq.pyx b/jq.pyx
index 9cb8807..293ea76 100644
--- a/jq.pyx
+++ b/jq.pyx
@@ -109,7 +109,7 @@ cdef object _jv_to_python(jv value):
property_key = jv_object_iter_key(value, idx)
property_value = jv_object_iter_value(value, idx)
try:
- python_value[jv_string_value(property_key).decode("utf-8")] = \
+ python_value[jv_string_to_py_string(property_key)] = \
_jv_to_python(property_value)
finally:
jv_free(property_key)
diff --git a/tests/jq_tests.py b/tests/jq_tests.py
index e5b0b5e..5b8e630 100644
--- a/tests/jq_tests.py
+++ b/tests/jq_tests.py
@@ -308,6 +308,13 @@ class TestJvToPython(object):
assert_equal({"a": {}, "b": {}}, program.input(text='{"a": {}, "b": {}}').first())
assert_equal({"": {"": {}}}, program.input(text='{"": {"": {}}}').first())
+ def test_object_keys_containing_null_characters_are_preserved(self):
+ program = jq.compile(".")
+
+ result = program.input({"a\x00b": None}).first()
+
+ assert_equal({"a\x00b": None}, result)
+
class TestConvenienceFunctions(object):
def test_first_function_with_json_value_input_returns_first_output_element(self):