commit af46edb: [Minor] Allow to get invisible content from html

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Sep 7 15:42:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-09-07 16:34:49 +0100
URL: https://github.com/rspamd/rspamd/commit/af46edb50eeba9d035a0c4d0bf32a800955c5ae9

[Minor] Allow to get invisible content from html

---
 src/lua/lua_html.cxx | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/lua/lua_html.cxx b/src/lua/lua_html.cxx
index 8767d1a11..b47a110d4 100644
--- a/src/lua/lua_html.cxx
+++ b/src/lua/lua_html.cxx
@@ -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)
 {


More information about the Commits mailing list