don't corrupt the unused buffer when reading child
This commit is contained in:
		
							parent
							
								
									31440a76a5
								
							
						
					
					
						commit
						d469128a48
					
				| @ -192,3 +192,42 @@ fn flatten_attribute() { | |||||||
|   serialize_and_validate!(model, content); |   serialize_and_validate!(model, content); | ||||||
|   deserialize_and_validate!(content, model, HtmlText); |   deserialize_and_validate!(content, model, HtmlText); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | #[test] | ||||||
|  | fn flatten_attribute_and_child() { | ||||||
|  |   init(); | ||||||
|  | 
 | ||||||
|  |   #[derive(Default, PartialEq, Debug, YaDeserialize, YaSerialize)] | ||||||
|  |   struct Node { | ||||||
|  |     #[yaserde(flatten)] | ||||||
|  |     base: Base, | ||||||
|  |     #[yaserde(child)] | ||||||
|  |     value: StringValue, | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   #[derive(Default, PartialEq, Debug, YaDeserialize, YaSerialize)] | ||||||
|  |   struct Base { | ||||||
|  |     #[yaserde(attribute)] | ||||||
|  |     id: String, | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   #[derive(Default, PartialEq, Debug, YaDeserialize, YaSerialize)] | ||||||
|  |   struct StringValue { | ||||||
|  |     #[yaserde(text)] | ||||||
|  |     string: String, | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   let model = Node { | ||||||
|  |     base: Base { | ||||||
|  |       id: "Foo".to_owned(), | ||||||
|  |     }, | ||||||
|  |     value: StringValue { | ||||||
|  |       string: "Bar".to_owned(), | ||||||
|  |     }, | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   let content = r#"<Node id="Foo"><value>Bar</value></Node>"#; | ||||||
|  | 
 | ||||||
|  |   serialize_and_validate!(model, content); | ||||||
|  |   deserialize_and_validate!(content, model, Node); | ||||||
|  | } | ||||||
|  | |||||||
| @ -160,6 +160,8 @@ pub fn parse( | |||||||
|               // If substruct's start element found then deserialize substruct
 |               // If substruct's start element found then deserialize substruct
 | ||||||
|               let value = <#struct_name as ::yaserde::YaDeserialize>::deserialize(reader)?; |               let value = <#struct_name as ::yaserde::YaDeserialize>::deserialize(reader)?; | ||||||
|               #value_label #action; |               #value_label #action; | ||||||
|  |               // read EndElement
 | ||||||
|  |               let _event = reader.next_event()?; | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|         }) |         }) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user