Skip to content

Commit

Permalink
Ensure, that map keys serialized as valid xml names
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Sep 2, 2022
1 parent 0336dcb commit a5e03b5
Show file tree
Hide file tree
Showing 6 changed files with 497 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Expand Up @@ -14,11 +14,17 @@

### Bug Fixes

- [#468]: Ensure, that serialization of map keys always produces valid XML names.
In particular, that means that maps with numeric and numeric-like keys (for
example, `"42"`) no longer can be serialized because [XML name] cannot start
from a digit

### Misc Changes

- [#468]: Content of `DeError::Unsupported` changed from `&'static str` to `Cow<'static, str>`

[#468]: https://github.com/tafia/quick-xml/pull/468
[XML name]: https://www.w3.org/TR/REC-xml/#NT-Name

## 0.24.0 -- 2022-08-28

Expand Down
16 changes: 16 additions & 0 deletions src/errors.rs
Expand Up @@ -188,6 +188,15 @@ pub mod serialize {
/// An attempt to deserialize to a type, that is not supported by the XML
/// store at current position, for example, attempt to deserialize `struct`
/// from attribute or attempt to deserialize binary data.
///
/// Serialized type cannot be represented in an XML due to violation of the
/// XML rules in the final XML document. For example, attempt to serialize
/// a `HashMap<{integer}, ...>` would cause this error because [XML name]
/// cannot start from a digit or a hyphen (minus sign). The same result
/// would occur if map key is a complex type that serialized not as
/// a primitive type (i.e. string, char, bool, unit struct or unit variant).
///
/// [XML name]: https://www.w3.org/TR/REC-xml/#sec-common-syn
Unsupported(Cow<'static, str>),
/// Too many events were skipped while deserializing a sequence, event limit
/// exceeded. The limit was provided as an argument
Expand Down Expand Up @@ -294,4 +303,11 @@ pub mod serialize {
Self::InvalidFloat(e)
}
}

impl From<fmt::Error> for DeError {
#[inline]
fn from(e: fmt::Error) -> Self {
Self::Custom(e.to_string())
}
}
}

0 comments on commit a5e03b5

Please sign in to comment.