X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fweb%2Fsrc%2Ftemplate_lualib.c;h=d3a5f89bbd5da892419c588e3f05bca0c06676e0;hp=f91b19ceb85c07f1778771cc29d72b1adfa94feb;hb=9fcdf0fe81f3c5142b8abd3f701dc3964549742a;hpb=047d4e45f6d26d54d2019ff3d12e372fae3f2e22;ds=sidebyside diff --git a/libs/web/src/template_lualib.c b/libs/web/src/template_lualib.c index f91b19ceb..d3a5f89bb 100644 --- a/libs/web/src/template_lualib.c +++ b/libs/web/src/template_lualib.c @@ -54,14 +54,50 @@ int template_L_parse(lua_State *L) return 3; } +int template_L_sanitize_utf8(lua_State *L) +{ + size_t len = 0; + const char *str = luaL_checklstring(L, 1, &len); + char *res = sanitize_utf8(str, len); + + if (res != NULL) + { + lua_pushstring(L, res); + free(res); + + return 1; + } + + return 0; +} + +int template_L_sanitize_pcdata(lua_State *L) +{ + size_t len = 0; + const char *str = luaL_checklstring(L, 1, &len); + char *res = sanitize_pcdata(str, len); + + if (res != NULL) + { + lua_pushstring(L, res); + free(res); + + return 1; + } + + return 0; +} + + /* module table */ static const luaL_reg R[] = { - {"parse", template_L_parse}, - {NULL, NULL} + { "parse", template_L_parse }, + { "sanitize_utf8", template_L_sanitize_utf8 }, + { "sanitize_pcdata", template_L_sanitize_pcdata }, + { NULL, NULL } }; LUALIB_API int luaopen_luci_template_parser(lua_State *L) { luaL_register(L, TEMPLATE_LUALIB_META, R); return 1; } -