summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-03-16 15:01:53 +0000
committerMichael Williamson <mike@zwobble.org>2023-03-16 15:01:53 +0000
commit7a09606ae38a18f814b40ec7041f189de2d65b5a (patch)
tree58e42ac3813fb3411f893f679a50ad60f93722c9
parent7a2648dfe150f532d1690fa8fbaf588789afaa84 (diff)
Handle null bytes in text input
-rw-r--r--jq.pyx2
-rw-r--r--tests/jq_tests.py9
2 files changed, 9 insertions, 2 deletions
diff --git a/jq.pyx b/jq.pyx
index 293ea76..174cea3 100644
--- a/jq.pyx
+++ b/jq.pyx
@@ -314,7 +314,7 @@ cdef class _ResultIterator(object):
self._ready = False
cdef jv_parser* parser = jv_parser_new(0)
cdef char* cbytes_input = PyBytes_AsString(bytes_input)
- jv_parser_set_buf(parser, cbytes_input, len(cbytes_input), 0)
+ jv_parser_set_buf(parser, cbytes_input, len(bytes_input), 0)
self._parser = parser
def __iter__(self):
diff --git a/tests/jq_tests.py b/tests/jq_tests.py
index 5b8e630..ebb7a6c 100644
--- a/tests/jq_tests.py
+++ b/tests/jq_tests.py
@@ -247,13 +247,20 @@ class TestJvToPython(object):
assert_equal("x", program.input(text='"x"').first())
assert_equal("xyz", program.input(text='"xyz"').first())
- def test_strings_containing_null_characters_are_preserved(self):
+ def test_given_json_value_then_string_containing_null_characters_are_preserved(self):
program = jq.compile(".")
result = program.input("a\x00b").first()
assert_equal("a\x00b", result)
+ def test_given_json_text_then_strings_containing_null_characters_are_preserved(self):
+ program = jq.compile(".")
+
+ result = program.input(text='"a\x00b"').first()
+
+ assert_equal("a\x00b", result)
+
def test_program_preserves_arrays(self):
program = jq.compile(".")