]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Html: Support 'hidden' attribute
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 11 Jul 2021 09:38:23 +0000 (10:38 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 11 Jul 2021 09:38:23 +0000 (10:38 +0100)
src/libserver/html/html.cxx
src/libserver/html/html_tag.hxx

index 0f5aefcdeeecf6d03f12175f182a08ff75544f58..28f26ec65274be9347389fba2daddc3a3aa42089 100644 (file)
@@ -66,6 +66,7 @@ auto html_components_map = frozen::make_unordered_map<frozen::string, html_compo
                                {"rel", html_component_type::RSPAMD_HTML_COMPONENT_REL},
                                {"alt", html_component_type::RSPAMD_HTML_COMPONENT_ALT},
                                {"id", html_component_type::RSPAMD_HTML_COMPONENT_ID},
+                               {"hidden", html_component_type::RSPAMD_HTML_COMPONENT_HIDDEN},
                });
 
 #define msg_debug_html(...)  rspamd_conditional_debug_fast (NULL, NULL, \
@@ -908,6 +909,7 @@ html_process_block_tag(rspamd_mempool_t *pool, struct html_tag *tag,
                                           struct html_content *hc) -> void
 {
        std::optional<css::css_value> maybe_fgcolor, maybe_bgcolor;
+       bool hidden = false;
 
        for (const auto &param : tag->components) {
                if (param.type == html_component_type::RSPAMD_HTML_COMPONENT_COLOR) {
@@ -921,12 +923,20 @@ html_process_block_tag(rspamd_mempool_t *pool, struct html_tag *tag,
                if (param.type == html_component_type::RSPAMD_HTML_COMPONENT_STYLE) {
                        tag->block = rspamd::css::parse_css_declaration(pool, param.value);
                }
+
+               if (param.type == html_component_type::RSPAMD_HTML_COMPONENT_HIDDEN) {
+                       hidden = true;
+               }
        }
 
        if (!tag->block) {
                tag->block = html_block::undefined_html_block_pool(pool);
        }
 
+       if (hidden) {
+               tag->block->set_display(false);
+       }
+
        if (maybe_fgcolor) {
                tag->block->set_fgcolor(maybe_fgcolor->to_color().value());
        }
@@ -2080,6 +2090,7 @@ TEST_CASE("html text extraction")
                         "<p style=\"font-size: 11px; line-height: 1.2; color: #555555; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; mso-line-height-alt: 14px; margin: 0;\">\n"
                         "&nbsp;</p>",
                                        " Sincerely,\n Skype Web\n"},
+                       {"lala<p hidden>fafa</p>", "lala\n"},
                        /* bgcolor propagation */
                        {"<a style=\"display: inline-block; color: #ffffff; background-color: #00aff0;\">\n"
                         "<span style=\"color: #00aff0;\">F</span>Rev<span style=\"opacity: 1;\"></span></span>ie<span style=\"opacity: 1;\"></span>"
index a221a48ffeadea219e3fbe859a58ddaacda07d9c..fab1b3867e8ef2ba66d0a40c8490bf9a2f483b0c 100644 (file)
@@ -41,6 +41,7 @@ enum class html_component_type : std::uint8_t {
        RSPAMD_HTML_COMPONENT_REL,
        RSPAMD_HTML_COMPONENT_ALT,
        RSPAMD_HTML_COMPONENT_ID,
+       RSPAMD_HTML_COMPONENT_HIDDEN,
 };
 
 /* Public tags flags */