]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Distinguish fatal and non fatal parsing errors
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 23 Jul 2021 19:04:14 +0000 (20:04 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 23 Jul 2021 19:04:14 +0000 (20:04 +0100)
src/libserver/css/css_parser.cxx
src/libserver/css/parse_error.hxx
src/libserver/html/html.cxx

index 4a545db4e51ab21eba67eeeb0b69b3263ee5f1d7..36550908a4186a455812254b74c491fd46abbc84 100644 (file)
@@ -606,7 +606,7 @@ css_parser::consume_input(const std::string_view &sv)
        const auto &rules = consumed_blocks->get_blocks_or_empty();
 
        if (rules.empty()) {
-               if (error.type == css_parse_error_type::PARSE_ERROR_UNKNOWN_ERROR) {
+               if (error.type == css_parse_error_type::PARSE_ERROR_NO_ERROR) {
                        return css_parse_error(css_parse_error_type::PARSE_ERROR_EMPTY,
                                        "no css rules consumed");
                }
index a493e993fdf842f92d656a05b40e81fbf44c596a..57ff0c0ce185982a50b26450f5663e72c6473e27 100644 (file)
@@ -31,10 +31,11 @@ enum class css_parse_error_type {
        PARSE_ERROR_UNKNOWN_OPTION,
        PARSE_ERROR_INVALID_SYNTAX,
        PARSE_ERROR_BAD_NESTING,
-       PARSE_ERROR_EMPTY,
        PARSE_ERROR_NYI,
        PARSE_ERROR_UNKNOWN_ERROR,
+       /* All above is treated as fatal error in parsing */
        PARSE_ERROR_NO_ERROR,
+       PARSE_ERROR_EMPTY,
 };
 
 struct css_parse_error {
@@ -45,6 +46,10 @@ struct css_parse_error {
                type(type), description(description) {}
        explicit css_parse_error (css_parse_error_type type = css_parse_error_type::PARSE_ERROR_NO_ERROR) :
                        type(type) {}
+
+       constexpr auto is_fatal(void) const -> bool {
+               return type < css_parse_error_type::PARSE_ERROR_NO_ERROR;
+       }
 };
 
 }
index 30607a8da5a4c2f9ea016814832842289630e225..088aad3693af374149b6e78d09f1183f713e0d38 100644 (file)
@@ -1791,11 +1791,14 @@ html_process_input(rspamd_mempool_t *pool,
                                                                std::move(hc->css_style));
 
                                                if (!ret_maybe.has_value()) {
-                                                       auto err_str = fmt::format("cannot parse css (error code: {}): {}",
-                                                                       static_cast<int>(ret_maybe.error().type),
-                                                                       ret_maybe.error().description.value_or("unknown error"));
-                                                       msg_info_pool ("cannot parse css: %*s",
-                                                                       (int) err_str.size(), err_str.data());
+                                                       if (ret_maybe.error().is_fatal()) {
+                                                               auto err_str = fmt::format(
+                                                                               "cannot parse css (error code: {}): {}",
+                                                                               static_cast<int>(ret_maybe.error().type),
+                                                                               ret_maybe.error().description.value_or("unknown error"));
+                                                               msg_info_pool ("cannot parse css: %*s",
+                                                                               (int) err_str.size(), err_str.data());
+                                                       }
                                                }
                                                else {
                                                        hc->css_style = ret_maybe.value();