From 27e448cf28cfe4ba24ab838cb6eb96711bf103a6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 2 Jul 2021 20:05:34 +0200 Subject: Do not callback for text that is empty after stripping --- src/HtmlParser.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/HtmlParser.c b/src/HtmlParser.c index efc9e27..287f322 100644 --- a/src/HtmlParser.c +++ b/src/HtmlParser.c @@ -299,7 +299,11 @@ static int html_parser_goto_script_end_tag(HtmlParser *self) { html_parser_advance_char(self); } } - return self->parse_callback(self, HTML_PARSE_JAVASCRIPT_CODE, self->callback_userdata); + + if(self->text_stripped.size > 0) + return self->parse_callback(self, HTML_PARSE_JAVASCRIPT_CODE, self->callback_userdata); + else + return 0; } static void html_parser_goto_comment_end(HtmlParser *self) { @@ -504,9 +508,11 @@ int html_parser_parse(const char *html_source, size_t len, HtmlParseCallback par } self.text.size = (self.source + self.offset) - self.text.data; strip(self.text.data, self.text.size, &self.text_stripped.data, &self.text_stripped.size, is_whitespace); - res = self.parse_callback(&self, HTML_PARSE_TEXT, self.callback_userdata); - if(res != 0) - return res; + if(self.text_stripped.size > 0) { + res = self.parse_callback(&self, HTML_PARSE_TEXT, self.callback_userdata); + if(res != 0) + return res; + } } } -- cgit v1.2.3