From: Vsevolod Stakhov Date: Fri, 11 Jun 2021 14:08:53 +0000 (+0100) Subject: [Project] Html/Css: Fix some issues found X-Git-Tag: 3.0~321 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0e68af8a70b3deffcbeb42fc8ccf1fa38bc9da38;p=rspamd.git [Project] Html/Css: Fix some issues found --- diff --git a/src/libserver/css/css_tokeniser.cxx b/src/libserver/css/css_tokeniser.cxx index f31fdc009..22544053c 100644 --- a/src/libserver/css/css_tokeniser.cxx +++ b/src/libserver/css/css_tokeniser.cxx @@ -360,7 +360,7 @@ auto css_tokeniser::consume_number() -> struct css_parser_token } if (i > offset) { - double num; + float num; /* I wish it was supported properly */ //auto conv_res = std::from_chars(&input[offset], &input[i], num); diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx index 1d13c2466..23dabc4d5 100644 --- a/src/libserver/html/html.cxx +++ b/src/libserver/html/html.cxx @@ -225,6 +225,18 @@ html_process_tag(rspamd_mempool_t *pool, return true; } +auto +html_component_from_string(const std::string_view &st) -> std::optional +{ + auto known_component_it = html_components_map.find(st); + + if (known_component_it != html_components_map.end()) { + return known_component_it->second; + } + else { + return std::nullopt; + } +} static auto find_tag_component_name(rspamd_mempool_t *pool, @@ -1048,7 +1060,6 @@ html_process_input(rspamd_mempool_t *pool, struct rspamd_url *url = NULL; gint len, href_offset = -1; struct html_tag *cur_tag = NULL, *content_tag = NULL; - std::vector blocks_stack; std::vector tags_stack; struct tag_content_parser_state content_parser_env; @@ -1614,15 +1625,8 @@ html_process_input(rspamd_mempool_t *pool, } if (cur_tag->flags & FL_BLOCK) { - struct html_block *bl; - if (cur_tag->flags & FL_CLOSING) { - /* Just remove block element from the queue if any */ - if (!blocks_stack.empty()) { - blocks_stack.pop_back(); - } - } - else { + if (!(cur_tag->flags & FL_CLOSING)) { html_process_block_tag(pool, cur_tag, hc); } } diff --git a/src/libserver/html/html_tag.hxx b/src/libserver/html/html_tag.hxx index 251ba148c..906dc15d4 100644 --- a/src/libserver/html/html_tag.hxx +++ b/src/libserver/html/html_tag.hxx @@ -39,6 +39,12 @@ enum class html_component_type : std::uint8_t { RSPAMD_HTML_COMPONENT_REL, RSPAMD_HTML_COMPONENT_ALT, }; +/** + * Returns component type from a string + * @param st + * @return + */ +auto html_component_from_string(const std::string_view &st) -> std::optional; using html_tag_extra_t = std::variant; struct html_tag_component { @@ -73,6 +79,15 @@ struct html_tag { return std::nullopt; } + + auto find_component(std::optional what) const -> std::optional + { + if (what) { + return find_component(what.value()); + } + + return std::nullopt; + } }; }