diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2010-11-12 22:37:50 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2010-11-12 22:37:50 +0000 |
commit | 09e71acf6baa4597bc0948046c3983a8ac2bda09 (patch) | |
tree | 8e8244307c94501e091c51654250adc62486df57 /libs/web/src/template_lualib.c | |
parent | 98d72baa347c26ebff9f24764564f836276638b1 (diff) |
libs/web: add UTF-8 validation and pcdata escaping C routines to template parser
Diffstat (limited to 'libs/web/src/template_lualib.c')
-rw-r--r-- | libs/web/src/template_lualib.c | 42 |
1 files changed, 39 insertions, 3 deletions
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; } - |