From 09e71acf6baa4597bc0948046c3983a8ac2bda09 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 12 Nov 2010 22:37:50 +0000 Subject: libs/web: add UTF-8 validation and pcdata escaping C routines to template parser --- libs/web/src/template_lualib.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'libs/web/src/template_lualib.c') diff --git a/libs/web/src/template_lualib.c b/libs/web/src/template_lualib.c index f91b19ceb8..d3a5f89bbd 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; } - -- cgit v1.2.3