]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Html/Css: Fix some issues found
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 Jun 2021 14:08:53 +0000 (15:08 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 Jun 2021 14:09:10 +0000 (15:09 +0100)
src/libserver/css/css_tokeniser.cxx
src/libserver/html/html.cxx
src/libserver/html/html_tag.hxx

index f31fdc009d087f73f86236009f26fb1c0a2a21a9..22544053c0f1ff6c5ad8dec6f40b27ca56553b75 100644 (file)
@@ -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);
index 1d13c24660060e88ab959551ead33ac3e410652e..23dabc4d5a208f502a044feb45a57bea3e8fa800 100644 (file)
@@ -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<html_component_type>
+{
+       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<html_block *> blocks_stack;
        std::vector<html_tag *> 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);
                                        }
                                }
index 251ba148c0fd36852f62c024ebeee3dd9b34e814..906dc15d4e7075520ba5775dfc8974a827d89ff2 100644 (file)
@@ -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<html_component_type>;
 
 using html_tag_extra_t = std::variant<std::monostate, struct rspamd_url *, struct html_image *>;
 struct html_tag_component {
@@ -73,6 +79,15 @@ struct html_tag {
 
                return std::nullopt;
        }
+
+       auto find_component(std::optional<html_component_type> what) const -> std::optional<std::string_view>
+       {
+               if (what) {
+                       return find_component(what.value());
+               }
+
+               return std::nullopt;
+       }
 };
 
 }