mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
minidom: ensure prefix is extracted out of provided name when creating Element
I would have liked to handle all of this in `Element::new` only, but I also have to do it in `Element::builder` unfortunately because then element builder then pushes prefixes it gathered itself. Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
f151306fbe
commit
171e7f1f34
2 changed files with 21 additions and 9 deletions
|
@ -129,7 +129,16 @@ impl Element {
|
|||
attributes: BTreeMap<String, String>,
|
||||
children: Vec<Node>,
|
||||
) -> Element {
|
||||
// TODO split name and possible prefix.
|
||||
let (prefix, name) = split_element_name(name).unwrap();
|
||||
let namespace: String = namespace.into();
|
||||
let prefixes: Prefixes = match prefix {
|
||||
None => prefixes.into(),
|
||||
Some(_) => {
|
||||
let mut p = prefixes.into();
|
||||
p.insert(namespace.clone(), prefix);
|
||||
p
|
||||
},
|
||||
};
|
||||
Element {
|
||||
name,
|
||||
namespace,
|
||||
|
@ -189,14 +198,13 @@ impl Element {
|
|||
/// assert_eq!(bare.text(), "");
|
||||
/// ```
|
||||
pub fn bare<S: Into<String>, NS: Into<String>>(name: S, namespace: NS) -> Element {
|
||||
// TODO split name and possible prefix.
|
||||
Element {
|
||||
name: name.into(),
|
||||
namespace: namespace.into(),
|
||||
prefixes: Rc::new(Prefixes::default()),
|
||||
attributes: BTreeMap::new(),
|
||||
children: Vec::new(),
|
||||
}
|
||||
Element::new(
|
||||
name.into(),
|
||||
namespace.into(),
|
||||
BTreeMap::new(),
|
||||
BTreeMap::new(),
|
||||
Vec::new(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns a reference to the name of this element.
|
||||
|
|
|
@ -52,6 +52,10 @@ impl Prefixes {
|
|||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn insert<S: Into<String>>(&mut self, namespace: S, prefix: Option<String>) {
|
||||
self.prefixes.insert(namespace.into(), prefix);
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BTreeMap<String, Option<String>>> for Prefixes {
|
||||
|
|
Loading…
Reference in a new issue