File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -2789,8 +2789,16 @@ where
27892789 fn skip_whitespaces ( & mut self ) -> Result < ( ) , DeError > {
27902790 loop {
27912791 match self . peek ( ) ? {
2792+ // Skip only blank text nodes that contain a newline or carriage return
2793+ // (typical pretty-printed formatting). Preserve other blank text
2794+ // (e.g. single space) as they may be significant for some deserialization scenarios.
27922795 DeEvent :: Text ( e) if e. is_blank ( ) => {
2793- self . next ( ) ?;
2796+ let contains_newline = e. text . chars ( ) . any ( |c| c == '\n' || c == '\r' ) ;
2797+ if contains_newline {
2798+ self . next ( ) ?;
2799+ continue ;
2800+ }
2801+ break ;
27942802 }
27952803 _ => break ,
27962804 }
@@ -4648,7 +4656,6 @@ mod tests {
46484656 assert_eq ! ( de. next( ) . unwrap( ) , DeEvent :: Text ( " " . into( ) ) ) ;
46494657 assert_eq ! ( de. next( ) . unwrap( ) , DeEvent :: End ( BytesEnd :: new( "tag" ) ) ) ;
46504658 assert_eq ! ( de. next( ) . unwrap( ) , DeEvent :: Eof ) ;
4651- // Passes as expected
46524659 }
46534660
46544661 // start::text::text has no difference from start::text
Original file line number Diff line number Diff line change @@ -47,7 +47,6 @@ mod text {
4747
4848 let item: Item = from_str ( r#"<root>content </root>"# ) . unwrap ( ) ;
4949
50- // Passes as expected
5150 assert_eq ! (
5251 item,
5352 Item {
@@ -66,7 +65,6 @@ mod text {
6665
6766 let item: Item = from_str ( r#"<root> </root>"# ) . unwrap ( ) ;
6867
69- // Fails: called `Result::unwrap()` on an `Err` value: Custom("missing field `$text`")
7068 assert_eq ! (
7169 item,
7270 Item {
You can’t perform that action at this time.
0 commit comments