Skip to content

Commit 582ea3a

Browse files
committed
Preserve whitespaces for string primitive types
1 parent 26785e3 commit 582ea3a

File tree

8 files changed

+179
-94
lines changed

8 files changed

+179
-94
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Now references to entities (as predefined, such as `<`, as user-defined) repo
2020
Caller can parse the content of the entity and stream events from it as it is required by the
2121
XML specification. See the updated `custom_entities` example!
2222

23+
Implement whitespace behavior in the standard, which says string primitive types should
24+
preserve whitespace, while all other primitives have collapse behavior.
25+
2326
### New Features
2427

2528
- [#863]: Add `Attributes::into_map_access(&str)` and `Attributes::into_deserializer()` when `serialize`

src/de/map.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ where
262262
QNameDeserializer::from_attr(QName(&slice[key]), decoder, &mut self.de.key_buf)?;
263263
seed.deserialize(de).map(Some)
264264
} else {
265+
self.de.skip_whitespaces()?;
265266
// try getting from events (<key>value</key>)
266267
match self.de.peek()? {
267268
// We shouldn't have both `$value` and `$text` fields in the same
@@ -318,6 +319,7 @@ where
318319
debug_assert_eq!(self.start.name(), e.name());
319320
// Consume End
320321
self.de.next()?;
322+
self.de.skip_whitespaces()?;
321323
Ok(None)
322324
}
323325
// We cannot get `Eof` legally, because we always inside of the
@@ -563,7 +565,7 @@ where
563565
// We cannot use result of `peek()` directly because of borrow checker
564566
let _ = self.map.de.peek()?;
565567
match self.map.de.last_peeked() {
566-
DeEvent::Text(t) if t.is_empty() => visitor.visit_none(),
568+
DeEvent::Text(t) if t.is_blank() => visitor.visit_none(),
567569
DeEvent::Start(start) if self.map.should_skip_subtree(start) => {
568570
self.map.de.skip_next_tree()?;
569571
visitor.visit_none()
@@ -935,6 +937,7 @@ where
935937
T: DeserializeSeed<'de>,
936938
{
937939
loop {
940+
self.map.de.skip_whitespaces()?;
938941
break match self.map.de.peek()? {
939942
// If we see a tag that we not interested, skip it
940943
#[cfg(feature = "overlapped-lists")]

0 commit comments

Comments
 (0)