commit 91ebd0c: [Fix] Various visibility fixes

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Jul 19 13:21:07 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-07-19 14:18:41 +0100
URL: https://github.com/rspamd/rspamd/commit/91ebd0c1653ecf3e4d6aa213fd4c886d3961c9b1 (HEAD -> master)

[Fix] Various visibility fixes

---
 src/libserver/html/html.cxx       | 20 +++++++++++++-------
 src/libserver/html/html_block.hxx | 10 ++++++++--
 src/libserver/html/html_tests.cxx |  2 +-
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx
index e3a70d809..73e6e62ff 100644
--- a/src/libserver/html/html.cxx
+++ b/src/libserver/html/html.cxx
@@ -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;
 				}
 			}
 		}
diff --git a/src/libserver/html/html_block.hxx b/src/libserver/html/html_block.hxx
index 01b5b17b9..59478fd6d 100644
--- a/src/libserver/html/html_block.hxx
+++ b/src/libserver/html/html_block.hxx
@@ -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
diff --git a/src/libserver/html/html_tests.cxx b/src/libserver/html/html_tests.cxx
index e98ab61c2..39644300a 100644
--- a/src/libserver/html/html_tests.cxx
+++ b/src/libserver/html/html_tests.cxx
@@ -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"


More information about the Commits mailing list