Browse Source

LibWeb: Parse <br/> into a self-closed br element

We were parsing "<br/>" as an open tag with the name "br/". This fixes
that specific scenario.

We also rename is_self_closing_tag() to is_void_element() to better fit
the specs.
Andreas Kling 5 years ago
parent
commit
88908be350
1 changed files with 9 additions and 2 deletions
  1. 9 2
      Libraries/LibWeb/Parser/HTMLParser.cpp

+ 9 - 2
Libraries/LibWeb/Parser/HTMLParser.cpp

@@ -45,7 +45,7 @@ static bool is_valid_in_attribute_name(char ch)
     return isalnum(ch) || ch == '_' || ch == '-';
     return isalnum(ch) || ch == '_' || ch == '-';
 }
 }
 
 
-static bool is_self_closing_tag(const StringView& tag_name)
+static bool is_void_element(const StringView& tag_name)
 {
 {
     return tag_name == "area"
     return tag_name == "area"
         || tag_name == "base"
         || tag_name == "base"
@@ -133,7 +133,7 @@ static bool parse_html_document(const StringView& html, Document& document, Pare
             node_stack[node_stack.size() - 2].append_child(new_element);
             node_stack[node_stack.size() - 2].append_child(new_element);
         }
         }
 
 
-        if (is_self_closing_tag(new_element->tag_name()))
+        if (is_void_element(new_element->tag_name()))
             close_tag();
             close_tag();
     };
     };
 
 
@@ -258,6 +258,13 @@ static bool parse_html_document(const StringView& html, Document& document, Pare
                 move_to_state(State::InAttributeList);
                 move_to_state(State::InAttributeList);
                 break;
                 break;
             }
             }
+            if (ch == '/' && peek(1) == '>') {
+                open_tag();
+                close_tag();
+                i += 1;
+                move_to_state(State::Free);
+                break;
+            }
             if (ch == '>') {
             if (ch == '>') {
                 commit_tag();
                 commit_tag();
                 move_to_state(State::Free);
                 move_to_state(State::Free);