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

Unexpected empty Text event when XML starts from a comment #363

Closed
Mingun opened this issue Feb 18, 2022 · 0 comments · Fixed by #398
Closed

Unexpected empty Text event when XML starts from a comment #363

Mingun opened this issue Feb 18, 2022 · 0 comments · Fixed by #398

Comments

@Mingun
Copy link
Collaborator

Mingun commented Feb 18, 2022

I noticed, that such XML generates an empty Text event that is redundant:

<!---->

The following tests failed (if placed into reader.rs):

#[cfg(test)]
mod test {
    use super::*;
    use crate::reader::Reader;

    #[test]
    fn start_with_comment_buffered() {
        let mut reader = Reader::from_str("<!---->other content");

        /*assert_eq!(
            reader.read_event_buffered(&mut Vec::new()).unwrap(),
            Event::Text(BytesText::from_escaped(b"".as_ref()))
        );*/
        assert_eq!(
            reader.read_event_buffered(&mut Vec::new()).unwrap(),
            Event::Comment(BytesText::from_escaped(b"".as_ref()))
        );
        assert_eq!(
            reader.read_event_buffered(&mut Vec::new()).unwrap(),
            Event::Text(BytesText::from_escaped(b"other content".as_ref()))
        );
    }

    #[test]
    fn start_with_comment_unbuffered() {
        let mut reader = Reader::from_str("<!---->other content");

        /*assert_eq!(
            reader.read_event_buffered(()).unwrap(),
            Event::Text(BytesText::from_escaped(b"".as_ref()))
        );*/
        assert_eq!(
            reader.read_event_buffered(()).unwrap(),
            Event::Comment(BytesText::from_escaped(b"".as_ref()))
        );
        assert_eq!(
            reader.read_event_buffered(()).unwrap(),
            Event::Text(BytesText::from_escaped(b"other content".as_ref()))
        );
    }
}

If you uncomment commented checks, then tests will pass.

There no need to generate redundant empty Text events, because otherwise we can say, why only one such event is generated? In my opinion empty Text event should be never generated

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

Successfully merging a pull request may close this issue.

1 participant