]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Various visibility fixes
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 19 Jul 2021 13:18:41 +0000 (14:18 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 19 Jul 2021 13:18:41 +0000 (14:18 +0100)
src/libserver/html/html.cxx
src/libserver/html/html_block.hxx
src/libserver/html/html_tests.cxx

index e3a70d8098e9e04d367f0bcf02b5128f0f42c3ff..73e6e62ff178d665b99cede6bd984353cef7d051 100644 (file)
@@ -1104,10 +1104,15 @@ html_append_tag_content(rspamd_mempool_t *pool,
                                is_visible = false;
                        }
                        else {
-                               is_transparent = true;
+                               if (tag->block->has_display() && tag->block->display == css::css_display_value::DISPLAY_HIDDEN) {
+                                       is_visible = false;
+                               }
+                               else {
+                                       is_transparent = true;
+                               }
                        }
                }
-               else if (tag->block->has_display()) {
+               else {
                        if (tag->block->display == css::css_display_value::DISPLAY_BLOCK) {
                                is_block = true;
                        }
@@ -1838,7 +1843,7 @@ html_process_input(rspamd_mempool_t *pool,
        }
 
        /* Propagate styles */
-       hc->traverse_block_tags([&hc](const html_tag *tag) -> bool {
+       hc->traverse_block_tags([&hc, &pool](const html_tag *tag) -> bool {
 
                if (hc->css_style) {
                        auto *css_block = hc->css_style->check_tag_block(tag);
@@ -1859,13 +1864,13 @@ html_process_input(rspamd_mempool_t *pool,
                                        tag->block->set_display(css::css_display_value::DISPLAY_HIDDEN);
                                }
                                else if (tag->flags & (CM_BLOCK | CM_TABLE)) {
-                                       tag->block->set_display(css::css_display_value::DISPLAY_BLOCK);
+                                       tag->block->set_display_implicit(css::css_display_value::DISPLAY_BLOCK);
                                }
                                else if (tag->flags & CM_ROW) {
-                                       tag->block->set_display(css::css_display_value::DISPLAY_TABLE_ROW);
+                                       tag->block->set_display_implicit(css::css_display_value::DISPLAY_TABLE_ROW);
                                }
                                else {
-                                       tag->block->set_display(css::css_display_value::DISPLAY_INLINE);
+                                       tag->block->set_display_implicit(css::css_display_value::DISPLAY_INLINE);
                                }
                        }
 
@@ -1877,7 +1882,8 @@ html_process_input(rspamd_mempool_t *pool,
                                        cld_tag->block->propagate_block(*tag->block);
                                }
                                else {
-                                       cld_tag->block = tag->block;
+                                       cld_tag->block = rspamd_mempool_alloc0_type(pool, html_block);
+                                       *cld_tag->block = *tag->block;
                                }
                        }
                }
index 01b5b17b9bf7cd523159955c5859211fdeb26aa6..59478fd6db53daef2335f12ce6c454624382ef16 100644 (file)
@@ -92,6 +92,10 @@ struct html_block {
                display = v;
                mask |= display_mask;
        }
+       /* Set display, do not set mask */
+       auto set_display_implicit(rspamd::css::css_display_value v) -> void  {
+               display = v;
+       }
        auto set_font_size(float fs, bool is_percent = false) -> void  {
                fs = is_percent ? (-fs) : fs;
                if (fs < INT8_MIN) {
@@ -121,9 +125,11 @@ struct html_block {
                simple_prop(fg_color_mask, fg_color, other.fg_color);
                simple_prop(bg_color_mask, bg_color, other.bg_color);
 
-               if (other.has_display() && !other.is_visible()) {
+               if (other.has_display()) {
                        simple_prop(display_mask, display, other.display);
-                       mask |= other.mask&(transparent_flag|invisible_flag);
+                       if (!other.is_visible()) {
+                               mask |= other.mask & (transparent_flag | invisible_flag);
+                       }
                }
 
                /* Sizes are very different
index e98ab61c230348bb832dd8a817eaa60981c8a5a1..39644300a70a2cb225092c3f7079a8554d669888 100644 (file)
@@ -122,7 +122,7 @@ TEST_CASE("html text extraction")
                         "    </P>\n"
                         "    <b>stuff</p>?\n"
                         "  </body>\n"
-                        "</html>", "Hello, world! test \ndata<>\nstuff?"},
+                        "</html>", "Hello, world! test \ndata<>\nstuff\n?"},
                        {"<p><!--comment-->test</br></hr><br>", "test\n"},
                        /* Tables */
                        {"<table>\n"