This is an automated email from the ASF dual-hosted git repository. mgrigorov pushed a commit to branch issue-rs-181-single-null-record in repository https://gitbox.apache.org/repos/asf/avro-rs.git
commit f08cdffa15a62ddce7399a3eef1e8f9fdfc9da95 Author: Martin Tzvetanov Grigorov <[email protected]> AuthorDate: Tue Apr 15 11:17:06 2025 +0300 Fixes #181 - Do not error if there is nothing to read Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> --- avro/src/reader.rs | 2 +- avro/tests/schema.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/avro/src/reader.rs b/avro/src/reader.rs index dd6d681..0830035 100644 --- a/avro/src/reader.rs +++ b/avro/src/reader.rs @@ -199,7 +199,7 @@ impl<'r, R: Read> Block<'r, R> { None => item, }; - if b_original == block_bytes.len() { + if b_original != 0 && b_original == block_bytes.len() { // from_avro_datum did not consume any bytes, so return an error to avoid an infinite loop return Err(Error::ReadBlock); } diff --git a/avro/tests/schema.rs b/avro/tests/schema.rs index 0c90615..c4a06c6 100644 --- a/avro/tests/schema.rs +++ b/avro/tests/schema.rs @@ -2353,3 +2353,19 @@ fn avro_rs_66_test_independent_canonical_form_missing_ref() -> TestResult { )); Ok(()) } + +#[test] +fn avro_rs_181_single_null_record() -> TestResult { + let mut buff = Cursor::new(Vec::new()); + let schema = Schema::parse_str(r#""null""#)?; + let mut writer = Writer::new(&schema, &mut buff); + writer.append(serde_json::Value::Null)?; + writer.into_inner()?; + buff.set_position(0); + + for val in Reader::new(buff)? { + assert_eq!(Value::Null, val?); + } + + Ok(()) +}
