aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/css
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-07-23 17:31:54 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-07-23 17:31:54 +0100
commitac8f149e0d78cd8ca2a776766ca78c1fd7655e40 (patch)
tree569c42db4c34f2402832b05e901f45fade9e93a6 /src/libserver/css
parenta57f64996e52cc87e51acfca68cda1335ae56d31 (diff)
downloadrspamd-ac8f149e0d78cd8ca2a776766ca78c1fd7655e40.tar.gz
rspamd-ac8f149e0d78cd8ca2a776766ca78c1fd7655e40.zip
[Minor] Css: Slightly fix error propagation
Diffstat (limited to 'src/libserver/css')
-rw-r--r--src/libserver/css/css_parser.cxx21
-rw-r--r--src/libserver/css/parse_error.hxx1
2 files changed, 15 insertions, 7 deletions
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<css_consumed_block> consume_css_rule(const std::string_view &sv);
- bool consume_input(const std::string_view &sv);
+ std::optional<css_parse_error> consume_input(const std::string_view &sv);
auto get_object_maybe(void) -> tl::expected<std::shared_ptr<css_style_sheet>, css_parse_error> {
if (style_object) {
@@ -599,13 +599,20 @@ css_parser::consume_css_rule(const std::string_view &sv) -> std::unique_ptr<css_
return rule_block;
}
-bool css_parser::consume_input(const std::string_view &sv)
+std::optional<css_parse_error>
+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,