Skip to content

Commit

Permalink
Add reserved namespace bindings.
Browse files Browse the repository at this point in the history
This adds xml and xmlns namespace bindings. These are defined at
https://www.w3.org/TR/xml-names11/#xmlReserved.
  • Loading branch information
wt authored and Mingun committed Sep 6, 2023
1 parent c9a1245 commit c05fda1
Show file tree
Hide file tree
Showing 4 changed files with 362 additions and 19 deletions.
9 changes: 7 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@

### New Features

- [#545]: Resolve well-known namespaces (`xml` and `xmlns`) to their appropriate URIs.
Also, enforce namespace constraints related to these well-known namespaces.

### Bug Fixes

### Misc Changes

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

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


Expand Down
23 changes: 23 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ pub enum Error {
EscapeError(EscapeError),
/// Specified namespace prefix is unknown, cannot resolve namespace for it
UnknownPrefix(Vec<u8>),
/// Error for when a reserved namespace is set incorrectly.
///
/// This error returned in following cases:
/// - the XML document attempts to bind `xml` prefix to something other than
/// `http://www.w3.org/XML/1998/namespace`
/// - the XML document attempts to bind `xmlns` prefix
/// - the XML document attempts to bind some prefix (except `xml`) to
/// `http://www.w3.org/XML/1998/namespace`
/// - the XML document attempts to bind some prefix to
/// `http://www.w3.org/2000/xmlns/`
InvalidPrefixBind {
/// The prefix that is tried to be bound
prefix: Vec<u8>,
/// Namespace to which prefix tried to be bound
namespace: Vec<u8>,
},
}

impl From<IoError> for Error {
Expand Down Expand Up @@ -121,6 +137,13 @@ impl fmt::Display for Error {
write_byte_string(f, prefix)?;
f.write_str("'")
}
Error::InvalidPrefixBind { prefix, namespace } => {
f.write_str("The namespace prefix '")?;
write_byte_string(f, prefix)?;
f.write_str("' cannot be bound to '")?;
write_byte_string(f, namespace)?;
f.write_str("'")
}
}
}
}
Expand Down
Loading

0 comments on commit c05fda1

Please sign in to comment.