From 7a09606ae38a18f814b40ec7041f189de2d65b5a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 16 Mar 2023 15:01:53 +0000 Subject: Handle null bytes in text input --- jq.pyx | 2 +- tests/jq_tests.py | 9 ++++++++- 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(".") -- cgit v1.2.3