]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix css style reading
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 19 Jul 2021 09:48:36 +0000 (10:48 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 19 Jul 2021 09:48:36 +0000 (10:48 +0100)
src/libserver/html/html.cxx

index beec91fac313c04010911bd6e9a709cd28fd5bbb..e3a70d8098e9e04d367f0bcf02b5128f0f42c3ff 100644 (file)
@@ -1759,10 +1759,33 @@ html_process_input(rspamd_mempool_t *pool,
                                                html_document_state = html_document_state::body;
                                        }
                                }
+
                                /* cur_tag here is a closing tag */
                                auto *next_cur_tag = html_check_balance(hc, cur_tag,
                                                c - start, p - start + 1);
 
+                               if (cur_tag->id == Tag_STYLE && allow_css) {
+                                       auto *opening_tag = cur_tag->parent;
+
+                                       if (opening_tag && opening_tag->content_offset < opening_tag->closing.start) {
+                                               auto ret_maybe = rspamd::css::parse_css(pool,
+                                                               {start + cur_tag->content_offset,
+                                                                cur_tag->closing.start - cur_tag->content_offset},
+                                                               std::move(hc->css_style));
+
+                                               if (!ret_maybe.has_value()) {
+                                                       auto err_str = fmt::format("cannot parse css (error code: {}): {}",
+                                                                       static_cast<int>(ret_maybe.error().type),
+                                                                       ret_maybe.error().description.value_or("unknown error"));
+                                                       msg_info_pool ("cannot parse css: %*s",
+                                                                       (int) err_str.size(), err_str.data());
+                                               }
+                                               else {
+                                                       hc->css_style = ret_maybe.value();
+                                               }
+                                       }
+                               }
+
                                if (next_cur_tag != nullptr) {
                                        cur_tag = next_cur_tag;
                                }
@@ -1798,25 +1821,6 @@ html_process_input(rspamd_mempool_t *pool,
                                        parent_tag = cur_tag->parent;
                                        g_assert(cur_tag->parent != &cur_closing_tag);
                                }
-
-                               if (cur_tag->id == Tag_STYLE && cur_tag->closing.start >  cur_tag->content_offset) {
-                                       if (allow_css) {
-                                               auto ret_maybe = rspamd::css::parse_css(pool,
-                                                               {start + cur_tag->content_offset, cur_tag->closing.start - cur_tag->content_offset},
-                                                               std::move(hc->css_style));
-
-                                               if (!ret_maybe.has_value()) {
-                                                       auto err_str = fmt::format("cannot parse css (error code: {}): {}",
-                                                                       static_cast<int>(ret_maybe.error().type),
-                                                                       ret_maybe.error().description.value_or("unknown error"));
-                                                       msg_info_pool ("cannot parse css: %*s",
-                                                                       (int) err_str.size(), err_str.data());
-                                               }
-                                               else {
-                                                       hc->css_style = ret_maybe.value();
-                                               }
-                                       }
-                               }
                        } /* if cur_tag != nullptr */
                        state = html_text_content;
                        p++;