mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
presence: Prevent two statuses from having the same lang.
This commit is contained in:
parent
0abac5ad2d
commit
e03a5a89e7
1 changed files with 14 additions and 1 deletions
|
@ -165,7 +165,9 @@ pub fn parse_presence(root: &Element) -> Result<Presence, Error> {
|
|||
return Err(Error::ParseError("Unknown child in status element."));
|
||||
}
|
||||
let lang = elem.attr("xml:lang").unwrap_or("").to_owned();
|
||||
statuses.insert(lang, elem.text());
|
||||
if let Some(_) = statuses.insert(lang, elem.text()) {
|
||||
return Err(Error::ParseError("Status element present twice for the same xml:lang."));
|
||||
}
|
||||
} else if elem.is("priority", ns::JABBER_CLIENT) {
|
||||
if priority.is_some() {
|
||||
return Err(Error::ParseError("More than one priority element in a presence."));
|
||||
|
@ -339,6 +341,17 @@ mod tests {
|
|||
assert_eq!(presence.statuses["fr"], "Là!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_multiple_statuses() {
|
||||
let elem: Element = "<presence xmlns='jabber:client'><status xml:lang='fr'>Here!</status><status xml:lang='fr'>Là!</status></presence>".parse().unwrap();
|
||||
let error = presence::parse_presence(&elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "Status element present twice for the same xml:lang.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_priority() {
|
||||
let elem: Element = "<presence xmlns='jabber:client'><priority>-1</priority></presence>".parse().unwrap();
|
||||
|
|
Loading…
Reference in a new issue