From be1f06afddb60e82f89f268036a01178d123a04e Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 18 Sep 2009 02:11:16 +0500 Subject: ejabberd2prosody: Fixed escape code processing when parsing strings. --- tools/erlparse.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/erlparse.lua b/tools/erlparse.lua index f2d410a3..bfec3b4d 100644 --- a/tools/erlparse.lua +++ b/tools/erlparse.lua @@ -45,16 +45,26 @@ local function isSpace(ch) return ch <= _space; end +local escapes = {["\\b"]="\b", ["\\d"]="\d", ["\\e"]="\e", ["\\f"]="\f", ["\\n"]="\n", ["\\r"]="\r", ["\\s"]="\s", ["\\t"]="\t", ["\\v"]="\v", ["\\\""]="\"", ["\\'"]="'", ["\\\\"]="\\"}; local function readString() read("\""); -- skip quote local slash = nil; local str = ""; while true do local ch = read(); - if ch == "\"" and not slash then break; end - str = str..ch; + if slash then + slash = slash..ch; + if not escapes[slash] then error("Unknown escape sequence: "..slash); end + str = str..escapes[slash]; + slash = nil; + elseif ch == "\"" then + break; + elseif ch == "\\" then + slash = ch; + else + str = str..ch; + end end - str = str:gsub("\\.", {["\\b"]="\b", ["\\d"]="\d", ["\\e"]="\e", ["\\f"]="\f", ["\\n"]="\n", ["\\r"]="\r", ["\\s"]="\s", ["\\t"]="\t", ["\\v"]="\v", ["\\\""]="\"", ["\\'"]="'", ["\\\\"]="\\"}); return str; end local function readAtom1() -- cgit v1.2.3