commit 4f0f3b6: [Minor] Process visibility property
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Jun 9 13:42:04 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-06-09 14:41:16 +0100
URL: https://github.com/rspamd/rspamd/commit/4f0f3b6b1030813ce46846e24313c8639deda4b3 (HEAD -> master)
[Minor] Process visibility property
---
src/libserver/css/css_property.hxx | 4 ++++
src/libserver/css/css_rule.cxx | 14 +++++++++++++-
src/libserver/css/css_rule.hxx | 10 +++++++++-
3 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/src/libserver/css/css_property.hxx b/src/libserver/css/css_property.hxx
index 82ef9808c..0e17e39fe 100644
--- a/src/libserver/css/css_property.hxx
+++ b/src/libserver/css/css_property.hxx
@@ -126,6 +126,10 @@ struct alignas(int) css_property {
return type == css_property_type::PROPERTY_DISPLAY;
}
+ auto is_visibility(void) const -> bool {
+ return type == css_property_type::PROPERTY_VISIBILITY;
+ }
+
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 238998009..2e84aaa1c 100644
--- a/src/libserver/css/css_rule.cxx
+++ b/src/libserver/css/css_rule.cxx
@@ -180,6 +180,16 @@ allowed_property_value(const css_property &prop, const css_consumed_block &parse
}
}
}
+ if (prop.is_visibility()) {
+ if (parser_block.is_token()) {
+ /* A single token */
+ const auto &tok = parser_block.get_token_or_empty();
+
+ if (tok.type == css_parser_token::token_type::ident_token) {
+ return css_value::maybe_display_from_string(tok.get_string_or_default(""));
+ }
+ }
+ }
if (prop.is_normal_number()) {
if (parser_block.is_token()) {
/* A single token */
@@ -369,10 +379,12 @@ css_declarations_block::merge_block(const css_declarations_block &other, merge_t
}
}
-void css_rule::add_value(const css_value &value) {
+void css_rule::add_value(const css_value &value)
+{
values.push_back(value);
}
+
TEST_SUITE("css rules") {
TEST_CASE("simple css rules") {
const std::vector<std::pair<const char *, std::vector<css_property>>> cases{
diff --git a/src/libserver/css/css_rule.hxx b/src/libserver/css/css_rule.hxx
index 113402905..3353382e7 100644
--- a/src/libserver/css/css_rule.hxx
+++ b/src/libserver/css/css_rule.hxx
@@ -76,7 +76,9 @@ public:
namespace rspamd::css {
-
+/**
+ * Class that is designed to hold css declaration (a set of rules)
+ */
class css_declarations_block {
public:
using rule_shared_ptr = std::shared_ptr<css_rule>;
@@ -96,9 +98,15 @@ public:
return rules;
}
+ /**
+ * Returns if a declaration block has some property
+ * @param prop
+ * @return
+ */
auto has_property(const css_property &prop) const -> bool {
return (rules.find(css_rule{prop}) != rules.end());
}
+
private:
robin_hood::unordered_flat_set<rule_shared_ptr, rule_shared_hash, rule_shared_eq> rules;
};
More information about the Commits
mailing list