]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Allow to get invisible content from html
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Sep 2021 15:34:49 +0000 (16:34 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Sep 2021 15:34:49 +0000 (16:34 +0100)
src/lua/lua_html.cxx

index 8767d1a117f7d12d3a61f6852380302081d7af71..b47a110d4176776a659d2cc6aaff93730774da40 100644 (file)
@@ -104,11 +104,19 @@ LUA_FUNCTION_DEF (html, get_images);
  */
 LUA_FUNCTION_DEF (html, foreach_tag);
 
+/***
+ * @method html:get_invisible()
+ * Returns invisible content of the HTML data
+ * @return
+ */
+LUA_FUNCTION_DEF (html, get_invisible);
+
 static const struct luaL_reg htmllib_m[] = {
        LUA_INTERFACE_DEF (html, has_tag),
        LUA_INTERFACE_DEF (html, has_property),
        LUA_INTERFACE_DEF (html, get_images),
        LUA_INTERFACE_DEF (html, foreach_tag),
+       LUA_INTERFACE_DEF (html, get_invisible),
        {"__tostring", rspamd_lua_class_tostring},
        {NULL, NULL}
 };
@@ -484,6 +492,22 @@ lua_html_foreach_tag (lua_State *L)
        return 0;
 }
 
+static gint
+lua_html_get_invisible (lua_State *L)
+{
+       LUA_TRACE_POINT;
+       auto *hc = lua_check_html (L, 1);
+
+       if (hc != NULL) {
+               lua_new_text (L, hc->invisible.c_str(), hc->invisible.size(), false);
+       }
+       else {
+               lua_newtable (L);
+       }
+
+       return 1;
+}
+
 static gint
 lua_html_tag_get_type (lua_State *L)
 {