Skip to content

Commit 7c96cb3

Browse files
committed
Added special handing of < inside attribute value
1 parent 70fdcf0 commit 7c96cb3

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/reader/parser.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ impl PullParser {
440440
self.into_state_continue(InsideReference(st))
441441
}
442442

443-
// Every character except " and ' is okay
443+
OpeningTagStart =>
444+
Some(self_error!(self; "Unexpected token inside attribute value: <")),
445+
446+
// Every character except " and ' and < is okay
444447
_ => self.append_str_continue(t.to_string().as_slice()),
445448
}
446449
}
@@ -1075,14 +1078,20 @@ mod tests {
10751078
)
10761079
)
10771080

1081+
macro_rules! test_data(
1082+
($d:expr) => ({
1083+
static DATA: &'static str = $d;
1084+
let r = BufReader::new(DATA.as_bytes());
1085+
let p = new_parser();
1086+
(r, p)
1087+
})
1088+
)
1089+
10781090
#[test]
1079-
fn semicolon_in_attribute_issue_3() {
1080-
static DATA: &'static str = r#"
1091+
fn semicolon_in_attribute_value__issue_3() {
1092+
let (mut r, mut p) = test_data!(r#"
10811093
<a attr="zzz;zzz" />
1082-
"#;
1083-
let mut r = BufReader::new(DATA.as_bytes());
1084-
1085-
let mut p = new_parser();
1094+
"#);
10861095

10871096
expect_event!(r, p, events::StartDocument { .. });
10881097
expect_event!(r, p, events::StartElement { ref name, ref attributes, ref namespace }
@@ -1094,4 +1103,16 @@ mod tests {
10941103
expect_event!(r, p, events::EndElement { ref name } if *name == Name::new_local("a"));
10951104
expect_event!(r, p, events::EndDocument);
10961105
}
1106+
1107+
#[test]
1108+
fn opening_tag_in_attribute_value() {
1109+
let (mut r, mut p) = test_data!(r#"
1110+
<a attr="zzz<zzz" />
1111+
"#);
1112+
1113+
expect_event!(r, p, events::StartDocument { .. });
1114+
expect_event!(r, p, events::Error(ref e)
1115+
if e.msg() == "Unexpected token inside attribute value: <"
1116+
);
1117+
}
10971118
}

0 commit comments

Comments
 (0)