Skip to content

Yet another approach to disable trim #865

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
merged 10 commits into from
Jun 22, 2025
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Now references to entities (as predefined, such as `<`, as user-defined) repo
Caller can parse the content of the entity and stream events from it as it is required by the
XML specification. See the updated `custom_entities` example!

Implement whitespace behavior in the standard in `Deserializer`, which says string primitive
types should preserve whitespace, while all other primitives have collapse behavior.

### New Features

- [#863]: Add `Attributes::into_map_access(&str)` and `Attributes::into_deserializer()` when `serialize`
Expand All @@ -30,6 +33,7 @@ XML specification. See the updated `custom_entities` example!
- [#766]: Added new configuration option `allow_dangling_amp` which allows to have
a `&` not followed by `;` in the textual data which is required for some applications
for compatibility reasons.
- [#285]: Add ability to `quick_xml::de::Text` to access text with trimmed spaces

### Bug Fixes

Expand All @@ -40,6 +44,7 @@ XML specification. See the updated `custom_entities` example!
- [#766]: `BytesText::unescape` and `BytesText::unescape_with` replaced by `BytesText::decode`.
Now Text events does not contain escaped parts which are reported as `Event::GeneralRef`.

[#285]: https://github.com/tafia/quick-xml/issues/285
[#766]: https://github.com/tafia/quick-xml/pull/766
[#863]: https://github.com/tafia/quick-xml/pull/863
[general entity]: https://www.w3.org/TR/xml11/#gen-entity
Expand Down
9 changes: 9 additions & 0 deletions src/de/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ where
fn should_skip_subtree(&self, start: &BytesStart) -> bool {
self.de.reader.reader.has_nil_attr(&self.start) || self.de.reader.reader.has_nil_attr(start)
}

/// Skips whitespaces when they are not preserved
#[inline]
fn skip_whitespaces(&mut self) -> Result<(), DeError> {
// TODO: respect the `xml:space` attribute and probably some deserialized type sign
self.de.skip_whitespaces()
}
}

impl<'de, 'd, R, E> MapAccess<'de> for ElementMapAccess<'de, 'd, R, E>
Expand Down Expand Up @@ -262,6 +269,7 @@ where
QNameDeserializer::from_attr(QName(&slice[key]), decoder, &mut self.de.key_buf)?;
seed.deserialize(de).map(Some)
} else {
self.skip_whitespaces()?;
// try getting from events (<key>value</key>)
match self.de.peek()? {
// We shouldn't have both `$value` and `$text` fields in the same
Expand Down Expand Up @@ -935,6 +943,7 @@ where
T: DeserializeSeed<'de>,
{
loop {
self.map.skip_whitespaces()?;
break match self.map.de.peek()? {
// If we see a tag that we not interested, skip it
#[cfg(feature = "overlapped-lists")]
Expand Down
Loading