diff --git a/servo/src/servo/parser/html.rs b/servo/src/servo/parser/html.rs index 7e472081de2f..13c9273dc92d 100644 --- a/servo/src/servo/parser/html.rs +++ b/servo/src/servo/parser/html.rs @@ -15,6 +15,7 @@ enum token { to_start_opening_tag(str), to_end_opening_tag, to_end_tag(str), + to_self_close_tag, to_text(str), to_attr(str, str), to_doctype, @@ -131,10 +132,13 @@ impl methods for parser { coe_eof { ret to_eof; } } - ret alt self.state { + let token = alt self.state { ps_normal { self.parse_in_normal_state(ch) } ps_tag { self.parse_in_tag_state(ch) } - } + }; + + #debug["token=%?", token]; + ret token; } fn parse_in_normal_state(c: u8) -> token { @@ -195,8 +199,13 @@ impl methods for parser { ret to_end_opening_tag; } + if ch == ('/' as u8) { + self.state = ps_normal; + ret to_self_close_tag; + } + if !ch.is_alpha() { - fail "expected alphabetical in tag"; + fail #fmt("expected alphabetical in tag but found %c", ch as char); } // Parse an attribute. diff --git a/servo/src/servo/parser/html_builder.rs b/servo/src/servo/parser/html_builder.rs index f5545b8d8c40..93c77e5046e8 100644 --- a/servo/src/servo/parser/html_builder.rs +++ b/servo/src/servo/parser/html_builder.rs @@ -47,7 +47,6 @@ fn build_dom(scope: dom::node_scope, let mut cur = scope.new_node(dom::nk_element(element("html", ~es_div))); loop { let token = stream.recv(); - #debug["token=%?", token]; alt token { parser::to_eof { break; } parser::to_start_opening_tag("div") { @@ -80,7 +79,7 @@ fn build_dom(scope: dom::node_scope, parser::to_end_opening_tag { #debug("end opening tag"); } - parser::to_end_tag(_) { + parser::to_end_tag(_) | parser::to_self_close_tag { // TODO: Assert that the closing tag has the right name. // TODO: Fail more gracefully (i.e. according to the HTML5 // spec) if we close more tags than we open. diff --git a/servo/src/test/about-mozilla.html b/servo/src/test/about-mozilla.html new file mode 100644 index 000000000000..b392ddcad61c --- /dev/null +++ b/servo/src/test/about-mozilla.html @@ -0,0 +1,54 @@ + + + +The Book of Mozilla, 11:9 + + + + +

+Mammon slept. And the beast reborn spread over the earth and its numbers +grew legion. And they proclaimed the times and sacrificed crops unto the +fire, with the cunning of foxes. And they built a new world in their own +image as promised by the +sacred words, and spoke + of the beast with their children. Mammon awoke, and lo! it was +naught but a follower. +

+ +

+from The Book of Mozilla, 11:9
(10th Edition) +

+ + +