Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reserved namespace bindings. #545

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading