From: Vsevolod Stakhov Date: Fri, 23 Jul 2021 16:31:54 +0000 (+0100) Subject: [Minor] Css: Slightly fix error propagation X-Git-Tag: 3.0~105 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ac8f149e0d78cd8ca2a776766ca78c1fd7655e40;p=rspamd.git [Minor] Css: Slightly fix error propagation --- diff --git a/src/libserver/css/css_parser.cxx b/src/libserver/css/css_parser.cxx index 1ab46a4ec..4a545db4e 100644 --- a/src/libserver/css/css_parser.cxx +++ b/src/libserver/css/css_parser.cxx @@ -166,7 +166,7 @@ public: * Process a single css rule */ std::unique_ptr consume_css_rule(const std::string_view &sv); - bool consume_input(const std::string_view &sv); + std::optional consume_input(const std::string_view &sv); auto get_object_maybe(void) -> tl::expected, css_parse_error> { if (style_object) { @@ -599,13 +599,20 @@ css_parser::consume_css_rule(const std::string_view &sv) -> std::unique_ptr +css_parser::consume_input(const std::string_view &sv) { auto &&consumed_blocks = consume_css_blocks(sv); const auto &rules = consumed_blocks->get_blocks_or_empty(); if (rules.empty()) { - return false; + if (error.type == css_parse_error_type::PARSE_ERROR_UNKNOWN_ERROR) { + return css_parse_error(css_parse_error_type::PARSE_ERROR_EMPTY, + "no css rules consumed"); + } + else { + return error; + } } if (!style_object) { @@ -691,7 +698,7 @@ bool css_parser::consume_input(const std::string_view &sv) auto debug_str = consumed_blocks->debug_str(); msg_debug_css("consumed css: {%*s}", (int)debug_str.size(), debug_str.data()); - return true; + return std::nullopt; } auto @@ -779,12 +786,12 @@ auto parse_css(rspamd_mempool_t *pool, const std::string_view &st, processed_input = std::string_view{nspace, st.size()}; } - if (parser.consume_input(processed_input)) { + auto maybe_error = parser.consume_input(processed_input); + if (!maybe_error) { return parser.get_object_maybe(); } - return tl::make_unexpected(css_parse_error{css_parse_error_type::PARSE_ERROR_INVALID_SYNTAX, - "cannot parse input"}); + return tl::make_unexpected(maybe_error.value()); } auto diff --git a/src/libserver/css/parse_error.hxx b/src/libserver/css/parse_error.hxx index 450c49d68..a493e993f 100644 --- a/src/libserver/css/parse_error.hxx +++ b/src/libserver/css/parse_error.hxx @@ -31,6 +31,7 @@ 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, PARSE_ERROR_NO_ERROR,