commit fb4eb10: [Project] Html: Fix parent propagation

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Jul 6 15:42:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-07-06 16:36:46 +0100
URL: https://github.com/rspamd/rspamd/commit/fb4eb10d3e9a0d908d7606cb8aab0cf10db35299 (HEAD -> master)

[Project] Html: Fix parent propagation

---
 src/libserver/css/css_property.cxx | 3 ++-
 src/libserver/html/html.cxx        | 7 ++++++-
 src/libserver/html/html_block.hxx  | 7 ++++++-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/libserver/css/css_property.cxx b/src/libserver/css/css_property.cxx
index 1dd73026d..992d5a0b0 100644
--- a/src/libserver/css/css_property.cxx
+++ b/src/libserver/css/css_property.cxx
@@ -27,6 +27,7 @@ constexpr const auto prop_names_map = frozen::make_unordered_map<frozen::string,
 		{"font-size", css_property_type::PROPERTY_FONT_SIZE},
 		{"color", css_property_type::PROPERTY_COLOR},
 		{"bgcolor", css_property_type::PROPERTY_BGCOLOR},
+		{"background-color", css_property_type::PROPERTY_BGCOLOR},
 		{"background", css_property_type::PROPERTY_BACKGROUND},
 		{"height", css_property_type::PROPERTY_HEIGHT},
 		{"width", css_property_type::PROPERTY_WIDTH},
@@ -36,7 +37,7 @@ constexpr const auto prop_names_map = frozen::make_unordered_map<frozen::string,
 });
 
 /* Ensure that we have all cases listed */
-static_assert(prop_names_map.size() == static_cast<int>(css_property_type::PROPERTY_NYI));
+static_assert(prop_names_map.size() >= static_cast<int>(css_property_type::PROPERTY_NYI));
 
 auto token_string_to_property(const std::string_view &inp)
 	-> css_property_type
diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx
index 86265b74e..a026326e8 100644
--- a/src/libserver/html/html.cxx
+++ b/src/libserver/html/html.cxx
@@ -1030,7 +1030,7 @@ html_append_content(struct html_content *hc, std::string_view data, bool transpa
 		/* Replace all visible characters with spaces */
 		auto start = std::next(hc->parsed.begin(), cur_offset);
 		std::replace_if(start, std::end(hc->parsed), [](const auto c) {
-			return g_ascii_isprint(c);
+			return !g_ascii_isspace(c);
 		}, ' ');
 	}
 
@@ -2073,6 +2073,11 @@ 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"
 			 " </p>",
 					" Sincerely,\n Skype Web\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>\n"
+			 "</span>w<span style=\"color: #00aff0;\">F<span style=\"opacity: 1;\">̹</span></span>",
+					" Review"},
 	};
 
 	rspamd_url_init(NULL);
diff --git a/src/libserver/html/html_block.hxx b/src/libserver/html/html_block.hxx
index 28ab3bae1..122d35aa3 100644
--- a/src/libserver/html/html_block.hxx
+++ b/src/libserver/html/html_block.hxx
@@ -115,11 +115,16 @@ struct html_block {
 		auto simple_prop = [&](auto mask_val, auto &our_val, auto other_val) constexpr -> void {
 			if (!(mask & mask_val) && (other.mask & mask_val)) {
 				our_val = other_val;
+				mask |= mask_val;
 			}
 		};
 		simple_prop(fg_color_mask, fg_color, other.fg_color);
 		simple_prop(bg_color_mask, bg_color, other.bg_color);
-		simple_prop(display_mask, display, other.display);
+
+		if (other.has_display() && !other.is_visible()) {
+			simple_prop(display_mask, display, other.display);
+			mask |= other.mask&(transparent_flag|invisible_flag);
+		}
 
 		/* Sizes are very different
 		 * We can have multiple cases:


More information about the Commits mailing list