netvl / xml-rs

An XML library in Rust
MIT License
461 stars 113 forks source link

EventReader never return Result::Err after document end #222

Closed chabapok closed 1 year ago

chabapok commented 2 years ago

EventReader never return Result::Err after document end. It returns Ok(EndDocument) over and over instead. It does not depend on the flag ignore_end_of_stream.

So, next code stuck in an endless loop:

use std::io::{BufReader, Cursor};
use xml::{EventReader, ParserConfig};

fn main() {

    let content = "<a></a>";

    let reader = BufReader::new(Cursor::new(content));
    let mut parser = EventReader::new_with_config(reader, ParserConfig::new().ignore_end_of_stream(true /* or false  */) );

    loop {
        if let Err(_) = parser.next() {
            break;
        }
    }
}
kornelski commented 1 year ago

This is by design. If the document is well-formed, you will never get Err. You should break on Ok(EndDocument) too.