]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Fix hex colors parsing
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 8 Jul 2021 15:10:10 +0000 (16:10 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 8 Jul 2021 15:10:10 +0000 (16:10 +0100)
src/libserver/css/css_value.cxx
src/libserver/html/html.cxx

index 799d5f8efcf08e0bff2642bc528fd59ddec1ac64..704905cd48a5879592cbcb5ead5040544dcfba5f 100644 (file)
@@ -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;
index b3080bd88fc97a0bb83d4e593379d4e77f04b1e0..346f87644029f44ece3c859e766b9258760906ca 100644 (file)
@@ -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"},