TAMER: Fail on empty fragment ids (and fix underlying problem)

master
Mike Gerwitz 2020-01-12 01:25:59 -05:00
parent a0893da577
commit 10b9caa7ad
2 changed files with 23 additions and 0 deletions

View File

@ -138,6 +138,11 @@
<apply-templates mode="preproc:compile-fragments" />
</template>
<!-- Do not compile these as consts -->
<template mode="preproc:compile-fragments" priority="9"
match="lv:meta/lv:prop/lv:const">
<!-- ignore -->
</template>
<template mode="preproc:compile-fragments" priority="5"
match="lv:meta/lv:prop">

View File

@ -507,6 +507,7 @@ impl<'i, B: BufRead, I: Interner<'i>> XmloReader<'i, B, I> {
let id = filtered
.find(|attr| attr.key == b"id")
.filter(|attr| &*attr.value != b"")
.map_or(Err(XmloError::UnassociatedFragment), |attr| {
Ok(unsafe { interner.intern_utf8_unchecked(&attr.value) })
})?;
@ -1185,6 +1186,23 @@ mod test {
}
}
// Yes, this happened.
fn fragment_fails_with_empty_id(sut, interner) {
sut.reader.next_event = Some(Box::new(|_, _| {
Ok(XmlEvent::Start(MockBytesStart::new(
b"preproc:fragment",
Some(MockAttributes::new(vec![MockAttribute::new(
b"id", b"",
)])),
)))
}));
match sut.read_event() {
Err(XmloError::UnassociatedFragment) => (),
bad => panic!("expected XmloError: {:?}", bad),
}
}
fn fragment_fails_with_missing_text(sut, interner) {
sut.reader.next_text = Some(Err(XmlError::TextNotFound));