]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Use traverse over all tags
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 Jun 2021 15:36:31 +0000 (16:36 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 11 Jun 2021 15:36:31 +0000 (16:36 +0100)
src/libserver/html/html.cxx
src/libserver/html/html.hxx
src/lua/lua_html.cxx

index 1cbc1f1051b04e005eb2881b97f6b3285d50d298..e727639aa7d1f9cab0d933e6b032b4bca936cda2 100644 (file)
@@ -1643,7 +1643,7 @@ html_process_input(rspamd_mempool_t *pool,
                }
        }
 
-       hc->traverse_tags([](const html_tag *tag) -> bool {
+       hc->traverse_block_tags([](const html_tag *tag) -> bool {
                /* Summarize content length from children */
                for (const auto *cld_tag : tag->children) {
                        tag->content_length += cld_tag->content_length;
index c75d84ea4855760162209f210e8c4c3106782834..3fd778ade56964a510ff7b2efa4162fbe2b35338 100644 (file)
@@ -63,7 +63,7 @@ struct html_content {
                PRE_ORDER,
                POST_ORDER
        };
-       auto traverse_tags(fu2::function<bool(const html_tag *)> &&func,
+       auto traverse_block_tags(fu2::function<bool(const html_tag *)> &&func,
                                        traverse_type how = traverse_type::PRE_ORDER) const -> bool {
 
                if (root_tag == nullptr) {
@@ -103,6 +103,18 @@ struct html_content {
                }
        }
 
+       auto traverse_all_tags(fu2::function<bool(const html_tag *)> &&func) const -> bool {
+               for (const auto &tag : all_tags) {
+                       if (!(tag->flags & (FL_CLOSING|FL_XML))) {
+                               if (!func(tag.get())) {
+                                       return false;
+                               }
+                       }
+               }
+
+               return true;
+       }
+
 private:
        ~html_content() = default;
 };
index 058ef401f60cbcad89928a4f33a1667ba6f2b5f6..7e17f835f6ef96edef849cd69f26dd703366d7e4 100644 (file)
@@ -431,7 +431,7 @@ lua_html_foreach_tag (lua_State *L)
        }
 
        if (hc && (any || !tags.empty()) && lua_isfunction (L, 3)) {
-               hc->traverse_tags([&](const rspamd::html::html_tag *tag) -> bool {
+               hc->traverse_all_tags([&](const rspamd::html::html_tag *tag) -> bool {
                        if (tag && (any || tags.contains(tag->id))) {
                                lua_pushvalue(L, 3);