Skip to content

Commit a5e03b5

Browse files
committed
Ensure, that map keys serialized as valid xml names
1 parent 0336dcb commit a5e03b5

File tree

6 files changed

+497
-8
lines changed

6 files changed

+497
-8
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414

1515
### Bug Fixes
1616

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

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

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

2329
## 0.24.0 -- 2022-08-28
2430

src/errors.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ pub mod serialize {
188188
/// An attempt to deserialize to a type, that is not supported by the XML
189189
/// store at current position, for example, attempt to deserialize `struct`
190190
/// from attribute or attempt to deserialize binary data.
191+
///
192+
/// Serialized type cannot be represented in an XML due to violation of the
193+
/// XML rules in the final XML document. For example, attempt to serialize
194+
/// a `HashMap<{integer}, ...>` would cause this error because [XML name]
195+
/// cannot start from a digit or a hyphen (minus sign). The same result
196+
/// would occur if map key is a complex type that serialized not as
197+
/// a primitive type (i.e. string, char, bool, unit struct or unit variant).
198+
///
199+
/// [XML name]: https://www.w3.org/TR/REC-xml/#sec-common-syn
191200
Unsupported(Cow<'static, str>),
192201
/// Too many events were skipped while deserializing a sequence, event limit
193202
/// exceeded. The limit was provided as an argument
@@ -294,4 +303,11 @@ pub mod serialize {
294303
Self::InvalidFloat(e)
295304
}
296305
}
306+
307+
impl From<fmt::Error> for DeError {
308+
#[inline]
309+
fn from(e: fmt::Error) -> Self {
310+
Self::Custom(e.to_string())
311+
}
312+
}
297313
}

0 commit comments

Comments
 (0)