From 0d28bf935a8482e7932584f9d55415053b96435e Mon Sep 17 00:00:00 2001 From: lxsang Date: Wed, 17 Jun 2020 23:58:11 +0200 Subject: [PATCH] disable unescape --- APIs/utils.lua | 37 ++++++++++++++++++++++++------------- lib/asl/json.c | 4 ++-- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/APIs/utils.lua b/APIs/utils.lua index 539a114..93c4728 100644 --- a/APIs/utils.lua +++ b/APIs/utils.lua @@ -49,20 +49,31 @@ function utils.decodeURI(url) end function utils.unescape(s) - local replacements = { - ["\\\\"] = "\\" , - ['\\"'] = '"' , - ["\\n"] = "\n" , - ["\\t"] = "\t" , - ["\\b"] = "\b" , - ["\\f"] = "\f" , - ["\\r"] = "\r" - } - local out = s - for k,v in pairs(replacements) do - out = out:gsub(k,v) + local str = "" + local escape = false + local esc_map = {b = '\b', f = '\f', n = '\n', r = '\r', t = '\t'} + for c in s:gmatch"." do + if c ~= '\\' then + if escape then + if esc_map[c] then + str = str..esc_map[c] + else + str = str..c + end + else + str = str..c + end + escape = false + else + if escape then + str = str..c + escape = false + else + escape = true + end + end end - return out + return str end function utils.file_exists(name) diff --git a/lib/asl/json.c b/lib/asl/json.c index 9e158ba..509ce5a 100644 --- a/lib/asl/json.c +++ b/lib/asl/json.c @@ -113,14 +113,14 @@ static int process_token_string(lua_State* L, jsmntok_t* t, const char* s, int c //const char* replace_token[8] = {"\\","\"","\n","\t","\b","\f","\r","/"}; char * str = strndup(s+t[cid].start, t[cid].end-t[cid].start); // un escape the string - lua_getglobal(L, "utils"); + /*lua_getglobal(L, "utils"); lua_getfield(L, -1, "unescape"); lua_pushstring(L,str); if (lua_pcall(L, 1, 1, 0) != 0) printf("Error running function `unescape': %s\n",lua_tostring(L, -1)); if(str) free(str); str = (char*)luaL_checkstring(L,-1); - lua_settop(L, -3); + lua_settop(L, -3);*/ lua_pushstring(L,str); //stackDump(L); //lua_pushstring(L, str);