aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-19 00:16:11 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-19 00:16:11 +0200
commitfdfdf20d085a7c705477d878c11ed208577facb1 (patch)
tree3f57157c297faabf224997e00523d7070f0de6af /src
parent9b45f8fe806b78300109274e4c951f894ffbac70 (diff)
Revert tag name to previous after void tag end (such as <br>)
Diffstat (limited to 'src')
-rw-r--r--src/HtmlParser.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/HtmlParser.c b/src/HtmlParser.c
index 8b27d6d..861168e 100644
--- a/src/HtmlParser.c
+++ b/src/HtmlParser.c
@@ -102,6 +102,8 @@ static void html_parser_reset(HtmlParser *self) {
self->text.size = 0;
self->text_stripped.data = NULL;
self->text_stripped.size = 0;
+ self->tag_before_void_tag.data = NULL;
+ self->tag_before_void_tag.size = 0;
self->is_tag_void = 0;
self->inside_script_tag = 0;
self->unclosed_tags_offset = 0;
@@ -308,8 +310,10 @@ static void html_parser_parse_tag_start(HtmlParser *self) {
for(;;) {
char c = html_parser_next_char(self);
if(c == '>') {
- if(tag_name_found && self->is_tag_void)
+ if(tag_name_found && self->is_tag_void) {
self->parse_callback(self, HTML_PARSE_TAG_END, self->callback_userdata);
+ self->tag_name = self->tag_before_void_tag;
+ }
self->is_tag_void = 0;
if(self->inside_script_tag) {
@@ -323,7 +327,9 @@ static void html_parser_parse_tag_start(HtmlParser *self) {
html_parser_advance_char(self);
if(tag_name_found) {
self->parse_callback(self, HTML_PARSE_TAG_END, self->callback_userdata);
- if(!self->is_tag_void)
+ if(self->is_tag_void)
+ self->tag_name = self->tag_before_void_tag;
+ else
html_parser_try_pop_unclosed_tag(self);
}
self->is_tag_void = 0;
@@ -366,6 +372,7 @@ static void html_parser_parse_tag_start(HtmlParser *self) {
self->parse_callback(self, HTML_PARSE_ATTRIBUTE, self->callback_userdata);
} else {
/* tag name */
+ HtmlStringView prev_tag_name = self->tag_name;
self->tag_name = identifier;
html_string_view_to_lowercase(&self->tag_name);
tag_name_found = 1;
@@ -374,7 +381,9 @@ static void html_parser_parse_tag_start(HtmlParser *self) {
return;
}
self->is_tag_void = is_void_tag(&self->tag_name);
- if(!self->is_tag_void) {
+ if(self->is_tag_void) {
+ self->tag_before_void_tag = prev_tag_name;
+ } else {
html_parser_try_append_unclosed_tag(self, self->tag_name.data, self->tag_name.size);
self->inside_script_tag = string_view_equals(&self->tag_name, &script_tag);
}