From: Vsevolod Stakhov Date: Sat, 12 Jun 2021 13:40:12 +0000 (+0100) Subject: [Minor] Lowercase css before parsing X-Git-Tag: 3.0~312 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cad5c351eb35c714f512ed58d23c94f3495714a6;p=rspamd.git [Minor] Lowercase css before parsing --- 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(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);