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 4, 2023
1 parent 4a6e08b commit 2643ebf
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 17 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@

### 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

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


## 0.30.0 -- 2023-07-23

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 2643ebf

Please sign in to comment.