commit cad5c35: [Minor] Lowercase css before parsing

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Jun 12 13:42:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-06-12 14:40:12 +0100
URL: https://github.com/rspamd/rspamd/commit/cad5c351eb35c714f512ed58d23c94f3495714a6

[Minor] Lowercase css before parsing

---
 src/libserver/css/css_parser.cxx | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/libserver/css/css_parser.cxx b/src/libserver/css/css_parser.cxx
index 34d65aadc..d40520381 100644
--- a/src/libserver/css/css_parser.cxx
+++ b/src/libserver/css/css_parser.cxx
@@ -178,7 +178,7 @@ public:
 	}
 
 	/* Helper parser methods */
-	bool need_unescape(const std::string_view &sv);
+	static bool need_unescape(const std::string_view &sv);
 
 	~css_parser() {
 		if (!owned_style && style_object) {
@@ -778,7 +778,7 @@ auto parse_css(rspamd_mempool_t *pool, const std::string_view &st,
 	css_parser parser(other, pool);
 	std::string_view processed_input;
 
-	if (parser.need_unescape(st)) {
+	if (css_parser::need_unescape(st)) {
 		processed_input = rspamd::css::unescape_css(pool, st);
 	}
 	else {
@@ -805,8 +805,24 @@ auto
 parse_css_declaration(rspamd_mempool_t *pool, const std::string_view &st)
 	-> rspamd::html::html_block *
 {
+	std::string_view processed_input;
+
+	if (css_parser::need_unescape(st)) {
+		processed_input = rspamd::css::unescape_css(pool, st);
+	}
+	else {
+		/* Lowercase inplace */
+		auto *nspace = reinterpret_cast<char *>(rspamd_mempool_alloc(pool, st.length()));
+		auto *p = nspace;
+
+		for (const auto c : st) {
+			*p++ = g_ascii_tolower(c);
+		}
+
+		processed_input = std::string_view{nspace, (std::size_t)(p - nspace)};
+	}
 	auto &&res = process_declaration_tokens(pool,
-			get_rules_parser_functor(pool, st));
+			get_rules_parser_functor(pool, processed_input));
 
 	if (res) {
 		return res->compile_to_block(pool);


More information about the Commits mailing list