From af46edb50eeba9d035a0c4d0bf32a800955c5ae9 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 7 Sep 2021 16:34:49 +0100 Subject: [PATCH] [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) { -- 2.39.5