Skip to content

Commit c05fda1

Browse files
wtMingun
authored andcommitted
Add reserved namespace bindings.
This adds xml and xmlns namespace bindings. These are defined at https://www.w3.org/TR/xml-names11/#xmlReserved.
1 parent c9a1245 commit c05fda1

File tree

4 files changed

+362
-19
lines changed

4 files changed

+362
-19
lines changed

Changelog.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212

1313
### New Features
1414

15+
- [#545]: Resolve well-known namespaces (`xml` and `xmlns`) to their appropriate URIs.
16+
Also, enforce namespace constraints related to these well-known namespaces.
17+
1518
### Bug Fixes
1619

1720
### Misc Changes
1821

19-
- [#643] Bumped MSRV to 1.56. In practice the previous MSRV was incorrect in many cases.
20-
- [#643] Adopted Rust 2021 edition.
22+
- [#643]: Bumped MSRV to 1.56. In practice the previous MSRV was incorrect in many cases.
23+
- [#643]: Adopted Rust 2021 edition.
24+
- [#545]: Add new `Error` variant -- `Error::InvalidPrefixBind`
2125

26+
[#545]: https://github.com/tafia/quick-xml/pull/545
2227
[#643]: https://github.com/tafia/quick-xml/pull/643
2328

2429

src/errors.rs

+23
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ pub enum Error {
4747
EscapeError(EscapeError),
4848
/// Specified namespace prefix is unknown, cannot resolve namespace for it
4949
UnknownPrefix(Vec<u8>),
50+
/// Error for when a reserved namespace is set incorrectly.
51+
///
52+
/// This error returned in following cases:
53+
/// - the XML document attempts to bind `xml` prefix to something other than
54+
/// `http://www.w3.org/XML/1998/namespace`
55+
/// - the XML document attempts to bind `xmlns` prefix
56+
/// - the XML document attempts to bind some prefix (except `xml`) to
57+
/// `http://www.w3.org/XML/1998/namespace`
58+
/// - the XML document attempts to bind some prefix to
59+
/// `http://www.w3.org/2000/xmlns/`
60+
InvalidPrefixBind {
61+
/// The prefix that is tried to be bound
62+
prefix: Vec<u8>,
63+
/// Namespace to which prefix tried to be bound
64+
namespace: Vec<u8>,
65+
},
5066
}
5167

5268
impl From<IoError> for Error {
@@ -121,6 +137,13 @@ impl fmt::Display for Error {
121137
write_byte_string(f, prefix)?;
122138
f.write_str("'")
123139
}
140+
Error::InvalidPrefixBind { prefix, namespace } => {
141+
f.write_str("The namespace prefix '")?;
142+
write_byte_string(f, prefix)?;
143+
f.write_str("' cannot be bound to '")?;
144+
write_byte_string(f, namespace)?;
145+
f.write_str("'")
146+
}
124147
}
125148
}
126149
}

0 commit comments

Comments
 (0)