commit 83855b1: [Minor] Fix hex colors parsing

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Jul 8 15:14:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-07-08 16:10:10 +0100
URL: https://github.com/rspamd/rspamd/commit/83855b16bb7fb9c699cd7f4d935e58217bb41ab0 (HEAD -> master)

[Minor] Fix hex colors parsing

---
 src/libserver/css/css_value.cxx | 12 +++++++++---
 src/libserver/html/html.cxx     |  3 +++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/libserver/css/css_value.cxx b/src/libserver/css/css_value.cxx
index 799d5f8ef..704905cd4 100644
--- a/src/libserver/css/css_value.cxx
+++ b/src/libserver/css/css_value.cxx
@@ -40,10 +40,16 @@ namespace rspamd::css {
 
 auto css_value::maybe_color_from_string(const std::string_view &input)
 -> std::optional<css_value> {
-	auto found_it = css_colors_map.find(input);
 
-	if (found_it != css_colors_map.end()) {
-		return css_value{found_it->second};
+	if (input.size() > 1 && input.front() == '#') {
+		return css_value::maybe_color_from_hex(input.substr(1));
+	}
+	else {
+		auto found_it = css_colors_map.find(input);
+
+		if (found_it != css_colors_map.end()) {
+			return css_value{found_it->second};
+		}
 	}
 
 	return std::nullopt;
diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx
index b3080bd88..346f87644 100644
--- a/src/libserver/html/html.cxx
+++ b/src/libserver/html/html.cxx
@@ -2132,6 +2132,9 @@ TEST_CASE("html text extraction")
 			 "<span style=\"color: #00aff0;\">F</span>Rev<span style=\"opacity: 1;\"></span></span>ie<span style=\"opacity: 1;\"></span>"
 			 "</span>w<span style=\"color: #00aff0;\">F<span style=\"opacity: 1;\">̹</span></span>",
 					" Review"},
+			{"<td style=\"color:#ffffff\" bgcolor=\"#005595\">\n"
+			 "hello world\n"
+			 "</td>", "hello world"},
 			/* Colors */
 			{"goodbye <span style=\"COLOR: rgb(64,64,64)\">cruel</span>"
 			 "<span>world</span>", "goodbye cruelworld"},


More information about the Commits mailing list