Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequence '--' is not rejected in comments #131

Open
FraGag opened this issue Sep 6, 2016 · 3 comments
Open

Sequence '--' is not rejected in comments #131

FraGag opened this issue Sep 6, 2016 · 3 comments

Comments

@FraGag
Copy link

FraGag commented Sep 6, 2016

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 \' \'") })
@netvl
Copy link
Owner

netvl commented Sep 6, 2016

The same reasoning as in #130 applies here too.

@DemiMarie
Copy link

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?

@netvl
Copy link
Owner

netvl commented May 20, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants