tamer: ir::xir::reader: Disable quick-xml check_end_names

XIR must support tag mismatches; XIRT will validate them.

This is currently disabled in the linker's xmlo reader as well.

DEV-10863
main
Mike Gerwitz 2021-10-25 10:58:19 -04:00
parent d72ab3675c
commit e6f53c20fd
2 changed files with 26 additions and 1 deletions

View File

@ -65,8 +65,15 @@ pub struct XmlXirReader<B: BufRead> {
impl<B: BufRead> XmlXirReader<B> {
pub fn new(reader: B) -> Self {
let mut reader = quick_xml::Reader::from_reader(reader);
// XIR must support mismatched tags so that we are able to represent
// and reconstruct malformed inputs.
// XIRT will handle mismatch errors itself.
reader.check_end_names(false);
Self {
reader: quick_xml::Reader::from_reader(reader),
reader,
readbuf: Vec::new(),
// This capacity is largely arbitrary,
// but [`Token`]s are small enough that it likely does not

View File

@ -373,6 +373,24 @@ lines-->
);
}
// XIRT handles mismatch errors; XIR must explicitly support them.
#[test]
fn permits_mismatched_tags() {
let sut = Sut::new(r#"<root><child /></mismatch>"#.as_bytes());
let result = sut.collect::<Result<Vec<_>>>();
assert_eq!(
result.expect("parsing failed"),
vec![
Token::Open("root".unwrap_into(), DUMMY_SPAN),
Token::Open("child".unwrap_into(), DUMMY_SPAN),
Token::Close(None, DUMMY_SPAN),
Token::Close(Some("mismatch".unwrap_into()), DUMMY_SPAN),
],
);
}
// TODO: Enough information for error recovery and reporting.
#[test]
fn node_name_invalid_utf8() {