quick-xml
quick-xml copied to clipboard
Newlines in attributes are lost
Newlines in attributes are not encoded into XML escape sequence and are lost or re-parsing.
(https://stackoverflow.com/questions/2004386/how-to-save-newlines-in-xml-attribute)
This is indeed looks like a bug.
@idubrov Is this what you mean? I've wrote a test code on current master (https://github.com/tafia/quick-xml/commit/15ee0189da4515daebd2e4dfadf1b446958290ba) and made sure that it passed. Am I doing right?
#[test]
fn test_newlines_in_attribute_should_not_be_lost() {
let mut r = Reader::from_str("<tag1 attr1='line 1\nline 2'></tag1>");
r.trim_text(true);
let mut buf = Vec::new();
match r.read_event(&mut buf) {
Ok(Event::Start(ref e)) => match e.name() {
b"tag1" => {
let v = e.attributes().map(|a| a.unwrap().value).collect::<Vec<_>>();
assert_eq!(v[0].clone().into_owned(), b"line 1\nline 2");
}
_ => (),
},
_ => (),
}
}
Fixed long time ago.