aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-03-10 20:30:32 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-03-10 20:30:32 +0000
commita72f5e4ad9879531340e4a854692a17ba8650087 (patch)
tree32456d68bbc07ed5a1f428cb8e2dc793732f0ba2
parentba5b6773e24de6179e730ab59d9fe6e376b40c80 (diff)
downloadrspamd-a72f5e4ad9879531340e4a854692a17ba8650087.tar.gz
rspamd-a72f5e4ad9879531340e4a854692a17ba8650087.zip
[Minor] Css: Fix rules insertion
-rw-r--r--src/libserver/css/css_property.hxx11
-rw-r--r--src/libserver/css/css_rule.cxx22
-rw-r--r--src/libserver/css/css_rule.hxx2
3 files changed, 26 insertions, 9 deletions
diff --git a/src/libserver/css/css_property.hxx b/src/libserver/css/css_property.hxx
index b72b655f9..973000b39 100644
--- a/src/libserver/css/css_property.hxx
+++ b/src/libserver/css/css_property.hxx
@@ -102,23 +102,28 @@ struct alignas(int) css_property {
}
/* Helpers to define which values are valid for which properties */
- constexpr auto is_color(void) const -> bool {
+ auto is_color(void) const -> bool {
return type == css_property_type::PROPERTY_COLOR ||
type == css_property_type::PROPERTY_BACKGROUND ||
type == css_property_type::PROPERTY_BGCOLOR ||
type == css_property_type::PROPERTY_FONT_COLOR ||
type == css_property_type::PROPERTY_FONT;
}
- constexpr auto is_dimension(void) const -> bool {
+ auto is_dimension(void) const -> bool {
return type == css_property_type::PROPERTY_HEIGHT ||
type == css_property_type::PROPERTY_WIDTH ||
type == css_property_type::PROPERTY_FONT_SIZE ||
type == css_property_type::PROPERTY_FONT;
}
- constexpr auto is_normal_number(void) const -> bool {
+
+ auto is_normal_number(void) const -> bool {
return type == css_property_type::PROPERTY_OPACITY;
}
+ auto is_display(void) const -> bool {
+ return type == css_property_type::PROPERTY_DISPLAY;
+ }
+
auto operator==(const css_property &other) const { return type == other.type; }
};
diff --git a/src/libserver/css/css_rule.cxx b/src/libserver/css/css_rule.cxx
index a706c759c..684e5776f 100644
--- a/src/libserver/css/css_rule.cxx
+++ b/src/libserver/css/css_rule.cxx
@@ -47,10 +47,16 @@ void css_rule::merge_values(const css_rule &other)
});
}
-auto css_declarations_block::add_rule(rule_shared_ptr &&rule) -> void
+auto css_declarations_block::add_rule(rule_shared_ptr &&rule) -> bool
{
auto it = rules.find(rule);
auto &&remote_prop = rule->get_prop();
+ auto ret = true;
+
+ if (rule->get_values().size() == 0) {
+ /* Ignore rules with no values */
+ return false;
+ }
if (it != rules.end()) {
auto &&local_rule = *it;
@@ -61,7 +67,7 @@ auto css_declarations_block::add_rule(rule_shared_ptr &&rule) -> void
local_rule->override_values(*rule);
}
else {
- /* Ignore remote not important over local important */
+ /* Override remote not important over local important */
local_rule->merge_values(*rule);
}
}
@@ -70,7 +76,7 @@ auto css_declarations_block::add_rule(rule_shared_ptr &&rule) -> void
local_rule->override_values(*rule);
}
else {
- /* Ignore local not important over important */
+ /* Override local not important over important */
local_rule->merge_values(*rule);
}
}
@@ -81,6 +87,7 @@ auto css_declarations_block::add_rule(rule_shared_ptr &&rule) -> void
}
else if (remote_prop.flag == css_property_flag::FLAG_NOT_IMPORTANT) {
/* Ignore remote not important over local normal */
+ ret = false;
}
else {
/* Merge both */
@@ -88,6 +95,11 @@ auto css_declarations_block::add_rule(rule_shared_ptr &&rule) -> void
}
}
}
+ else {
+ rules.insert(std::move(rule));
+ }
+
+ return ret;
}
}
@@ -208,7 +220,7 @@ auto process_declaration_tokens(rspamd_mempool_t *pool,
if (next_tok.is_token()) {
const auto &parser_tok = next_tok.get_token_or_empty();
- if (parser_tok.type == css_parser_token::token_type::semicolon_token) {
+ if (parser_tok.type == css_parser_token::token_type::semicolon_token && cur_rule) {
ret.add_rule(std::move(cur_rule));
state = parse_property;
seen_not = false;
@@ -267,7 +279,7 @@ auto process_declaration_tokens(rspamd_mempool_t *pool,
if (state == parse_value) {
auto maybe_value = allowed_property_value(cur_property, next_tok);
- if (maybe_value) {
+ if (maybe_value && cur_rule) {
msg_debug_css("added value %s to the property %s",
maybe_value.value().debug_str().c_str(),
cur_property.to_string());
diff --git a/src/libserver/css/css_rule.hxx b/src/libserver/css/css_rule.hxx
index dd6158538..fa9f2a78e 100644
--- a/src/libserver/css/css_rule.hxx
+++ b/src/libserver/css/css_rule.hxx
@@ -111,7 +111,7 @@ public:
using rule_shared_hash = shared_ptr_hash<css_rule>;
using rule_shared_eq = shared_ptr_equal<css_rule>;
css_declarations_block() = default;
- auto add_rule(rule_shared_ptr &&rule) -> void;
+ auto add_rule(rule_shared_ptr &&rule) -> bool;
auto get_rules(void) const -> const auto & {
return rules;
}