-
Notifications
You must be signed in to change notification settings - Fork 39
fix #226: Index-Out-Of-Bounds panic when using #[serde(skip_serializing_if=..)] #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+183
−96
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cec6e27
fix #226: Index-Out-Of-Bounds panic when using #[serde(skip_serializi…
b150d4d
Issue #225 - Compare the deserialized result with the serialized one
martin-g 4a19a1b
Issue #226: Serialize the RecordField's default when skipping a field
martin-g b8c9562
fmt
martin-g 373b4f3
Do not try to track the fields with item_count.
martin-g 2a1cf2f
clippy + fmt
martin-g 9db884b
Add ASLv2 header for the new IT test
martin-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| use apache_avro::{AvroSchema, Schema, Writer, from_value}; | ||
| use apache_avro_test_helper::TestResult; | ||
| use serde::{Deserialize, Serialize, de::DeserializeOwned}; | ||
| use std::fmt::Debug; | ||
|
|
||
| fn ser_deser<T>(schema: &Schema, record: T) -> TestResult | ||
| where | ||
| T: Serialize + DeserializeOwned + Debug + PartialEq + Clone, | ||
| { | ||
| let record2 = record.clone(); | ||
| let mut writer = Writer::new(schema, vec![]); | ||
| writer.append_ser(record)?; | ||
| let bytes_written = writer.into_inner()?; | ||
|
|
||
| let reader = apache_avro::Reader::new(&bytes_written[..])?; | ||
| for value in reader { | ||
| let value = value?; | ||
| let deserialized = from_value::<T>(&value)?; | ||
| assert_eq!(deserialized, record2); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn avro_rs_226_index_out_of_bounds_with_serde_skip_serializing_skip_middle_field() -> TestResult { | ||
| #[derive(AvroSchema, Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
| struct T { | ||
| x: Option<i8>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| y: Option<String>, | ||
| z: Option<i8>, | ||
| } | ||
|
|
||
| ser_deser::<T>( | ||
| &T::get_schema(), | ||
| T { | ||
| x: None, | ||
| y: None, | ||
| z: Some(1), | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| #[test] | ||
| fn avro_rs_226_index_out_of_bounds_with_serde_skip_serializing_skip_first_field() -> TestResult { | ||
| #[derive(AvroSchema, Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
| struct T { | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| x: Option<i8>, | ||
| y: Option<String>, | ||
| z: Option<i8>, | ||
| } | ||
|
|
||
| ser_deser::<T>( | ||
| &T::get_schema(), | ||
| T { | ||
| x: None, | ||
| y: None, | ||
| z: Some(1), | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| #[test] | ||
| fn avro_rs_226_index_out_of_bounds_with_serde_skip_serializing_skip_last_field() -> TestResult { | ||
| #[derive(AvroSchema, Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
| struct T { | ||
| x: Option<i8>, | ||
| y: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| z: Option<i8>, | ||
| } | ||
|
|
||
| ser_deser::<T>( | ||
| &T::get_schema(), | ||
| T { | ||
| x: Some(0), | ||
| y: None, | ||
| z: None, | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| #[test] | ||
| #[ignore = "This test should be re-enabled once the serde-driven deserialization is implemented! PR #227"] | ||
| fn avro_rs_226_index_out_of_bounds_with_serde_skip_multiple_fields() -> TestResult { | ||
| #[derive(AvroSchema, Clone, Debug, Deserialize, PartialEq, Serialize)] | ||
| struct T { | ||
| no_skip1: Option<i8>, | ||
| #[serde(skip_serializing)] | ||
| skip_serializing: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| skip_serializing_if: Option<i8>, | ||
| #[serde(skip_deserializing)] | ||
| skip_deserializing: Option<String>, | ||
| #[serde(skip)] | ||
| skip: Option<String>, | ||
| no_skip2: Option<i8>, | ||
| } | ||
|
|
||
| ser_deser::<T>( | ||
| &T::get_schema(), | ||
| T { | ||
| no_skip1: Some(1), | ||
| skip_serializing: None, | ||
| skip_serializing_if: None, | ||
| skip_deserializing: None, | ||
| skip: None, | ||
| no_skip2: Some(2), | ||
| }, | ||
| ) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.