mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
minidom: normalize_attribute_value
This commit is contained in:
parent
990b3be712
commit
f01629a47a
1 changed files with 27 additions and 0 deletions
|
@ -176,6 +176,7 @@ impl Token {
|
||||||
let (s, _) = space0(s)?;
|
let (s, _) = space0(s)?;
|
||||||
let (s, delim) = one_of("'\"")(s)?;
|
let (s, delim) = one_of("'\"")(s)?;
|
||||||
let (s, value) = Self::parse_text(delim, s)?;
|
let (s, value) = Self::parse_text(delim, s)?;
|
||||||
|
let value = Self::normalize_attribute_value(value);
|
||||||
let (s, _) = char(delim)(s)?;
|
let (s, _) = char(delim)(s)?;
|
||||||
Ok((s, (name, value)))
|
Ok((s, (name, value)))
|
||||||
}
|
}
|
||||||
|
@ -249,6 +250,16 @@ impl Token {
|
||||||
}
|
}
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://www.w3.org/TR/2008/REC-xml-20081126/#AVNormalize
|
||||||
|
///
|
||||||
|
/// assumes normalize_newlines() already done
|
||||||
|
fn normalize_attribute_value(mut s: Cow<str>) -> Cow<str> {
|
||||||
|
if s.find("\t").is_some() || s.find("\n").is_some() {
|
||||||
|
s = Cow::from(s.replace(|c| c == '\t' || c == '\n', " "));
|
||||||
|
}
|
||||||
|
s
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -338,6 +349,22 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_attrs_normalized() {
|
||||||
|
assert_eq!(
|
||||||
|
Ok((&b""[..], Token::StartTag {
|
||||||
|
name: "a".into(),
|
||||||
|
attrs: vec![
|
||||||
|
attr("a", "x y"),
|
||||||
|
attr("b", " "),
|
||||||
|
attr("c", "a b"),
|
||||||
|
],
|
||||||
|
self_closing: false,
|
||||||
|
})),
|
||||||
|
Token::parse(b"<a a=\"x\ty\" b = '\r\n' c = 'a\r\rb'>")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_attrs_entities() {
|
fn test_attrs_entities() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in a new issue