Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@ryansg.com>2020-01-12 01:25:59 -0500
committerMike Gerwitz <mike.gerwitz@ryansg.com>2020-02-25 16:46:28 -0500
commit10b9caa7adc070e230cd1cb9e6a46c23abca089f (patch)
treee2d01d7a00caa48b4199ec3dc9ee028987e0c7e7
parenta0893da577d36e3cd9886770f7a269729b704706 (diff)
downloadtame-10b9caa7adc070e230cd1cb9e6a46c23abca089f.tar.gz
tame-10b9caa7adc070e230cd1cb9e6a46c23abca089f.tar.bz2
tame-10b9caa7adc070e230cd1cb9e6a46c23abca089f.zip
TAMER: Fail on empty fragment ids (and fix underlying problem)
-rw-r--r--src/current/compiler/fragments.xsl5
-rw-r--r--tamer/src/obj/xmlo/reader.rs18
2 files changed, 23 insertions, 0 deletions
diff --git a/src/current/compiler/fragments.xsl b/src/current/compiler/fragments.xsl
index cf41132..dbeead6 100644
--- a/src/current/compiler/fragments.xsl
+++ b/src/current/compiler/fragments.xsl
@@ -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">
diff --git a/tamer/src/obj/xmlo/reader.rs b/tamer/src/obj/xmlo/reader.rs
index 3f850fb..5e79cae 100644
--- a/tamer/src/obj/xmlo/reader.rs
+++ b/tamer/src/obj/xmlo/reader.rs
@@ -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));