aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/css/css_parser.cxx
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-03-23 15:14:07 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-03-23 15:14:07 +0000
commit61d518bf1d96f079f2eed66dd3101cac64d83e00 (patch)
tree3c149dbb8d210e9b35942af19df56512e6bcaa8a /src/libserver/css/css_parser.cxx
parentec88225473072493a0fad76864d25240e75bb5f4 (diff)
downloadrspamd-61d518bf1d96f079f2eed66dd3101cac64d83e00.tar.gz
rspamd-61d518bf1d96f079f2eed66dd3101cac64d83e00.zip
[Project] Css: Add preliminary stylesheet support
Diffstat (limited to 'src/libserver/css/css_parser.cxx')
-rw-r--r--src/libserver/css/css_parser.cxx13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libserver/css/css_parser.cxx b/src/libserver/css/css_parser.cxx
index 415039e19..f80386fc2 100644
--- a/src/libserver/css/css_parser.cxx
+++ b/src/libserver/css/css_parser.cxx
@@ -559,7 +559,7 @@ bool css_parser::consume_input(const std::string_view &sv)
return false;
}
- style_object = std::make_unique<css_style_sheet>();
+ style_object = std::make_unique<css_style_sheet>(pool);
for (auto &&rule : rules) {
/*
@@ -627,6 +627,10 @@ bool css_parser::consume_input(const std::string_view &sv)
msg_debug_css("processed %d rules",
(int)declarations_vec->get_rules().size());
+ for (auto &&selector : selectors_vec) {
+ style_object->add_selector_rule(std::move(selector),
+ declarations_vec);
+ }
}
}
}
@@ -677,15 +681,16 @@ get_selectors_parser_functor(rspamd_mempool_t *pool,
* Wrapper for the parser
*/
auto parse_css(rspamd_mempool_t *pool, const std::string_view &st) ->
- bool
+ tl::expected<std::unique_ptr<css_style_sheet>, css_parse_error>
{
css_parser parser(pool);
if (parser.consume_input(st)) {
- return true;
+ return parser.get_object_maybe();
}
- return false;
+ return tl::make_unexpected(css_parse_error{css_parse_error_type::PARSE_ERROR_INVALID_SYNTAX,
+ "cannot parse input"});
}
TEST_SUITE("css parser") {