Skip to content

Commit

Permalink
Merge pull request #545 from wt/bind_reserved_namespaces
Browse files Browse the repository at this point in the history
Add reserved namespace bindings.
  • Loading branch information
Mingun authored Sep 6, 2023
2 parents 04c14a5 + c05fda1 commit 349cb3f
Show file tree
Hide file tree
Showing 4 changed files with 449 additions and 135 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 349cb3f

Please sign in to comment.