commit ec9867e: [Minor] Distinguish fatal and non fatal parsing errors
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Jul 23 19:07:06 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-07-23 20:04:14 +0100
URL: https://github.com/rspamd/rspamd/commit/ec9867e8b66de81839c7d824991e2007ff8d989b (HEAD -> master)
[Minor] Distinguish fatal and non fatal parsing errors
---
src/libserver/css/css_parser.cxx | 2 +-
src/libserver/css/parse_error.hxx | 7 ++++++-
src/libserver/html/html.cxx | 13 ++++++++-----
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/libserver/css/css_parser.cxx b/src/libserver/css/css_parser.cxx
index 4a545db4e..36550908a 100644
--- a/src/libserver/css/css_parser.cxx
+++ b/src/libserver/css/css_parser.cxx
@@ -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");
}
diff --git a/src/libserver/css/parse_error.hxx b/src/libserver/css/parse_error.hxx
index a493e993f..57ff0c0ce 100644
--- a/src/libserver/css/parse_error.hxx
+++ b/src/libserver/css/parse_error.hxx
@@ -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;
+ }
};
}
diff --git a/src/libserver/html/html.cxx b/src/libserver/html/html.cxx
index 30607a8da..088aad369 100644
--- a/src/libserver/html/html.cxx
+++ b/src/libserver/html/html.cxx
@@ -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();
More information about the Commits
mailing list