xml-rs icon indicating copy to clipboard operation
xml-rs copied to clipboard

Sequence '--' is not rejected in comments

Open FraGag opened this issue 9 years ago • 3 comments

The sequence -- must not occur within a comment, but xml-rs fails to return an error when emitted with EventWriter in an XmlEvent::Comment. xml-rs correctly gives an error when attempting to parse the erroneous document.

Sample program to reproduce the problem:

extern crate xml;

use xml::reader::EventReader;
use xml::writer::EventWriter;
use xml::writer::events::XmlEvent;

fn main() {
    let mut v = Vec::new();
    {
        let mut ew = EventWriter::new(&mut v);
        ew.write(XmlEvent::start_element("root")).unwrap();
        ew.write(XmlEvent::comment("invalid -- invalid")).unwrap();
        ew.write(XmlEvent::end_element()).unwrap();
    }

    let er = EventReader::new(&v[..]);
    for ev in er {
        println!("{:?}", ev);
    }
}

Output:

Ok(StartDocument(1.0, utf-8, None))
Ok(StartElement(root, {"": "", "xml": "http://www.w3.org/XML/1998/namespace", "xmlns": "http://www.w3.org/2000/xmlns/"}))
Err(Error { pos: 1:58, kind: Syntax("Unexpected token \'--\' before \' \'") })

FraGag avatar Sep 06 '16 01:09 FraGag

The same reasoning as in #130 applies here too.

netvl avatar Sep 06 '16 10:09 netvl

What is the correct behavior here? Unlike with PCDATA, there is no way to escape - in a comment. Is it best to return an error here? Or to use some ad-hoc escaping strategy?

DemiMarie avatar May 12 '17 19:05 DemiMarie

I don't think escaping is viable. Having an error returned would be nice.

That said, it is interesting how other writers handle such things. Maybe I could borrow from them.

netvl avatar May 20 '17 03:05 netvl