From cc99208ab793ff03e4a0d030cfcb355756260fcb Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 16 Dec 2008 03:46:17 +0500 Subject: [PATCH] Fixed URL encoding to generate %0x instead of %x --- net/http.lua | 2 +- prosody | 2 +- tools/ejabberd2prosody.lua | 2 +- util/datamanager.lua | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/http.lua b/net/http.lua index e8a981b8..a661bb52 100644 --- a/net/http.lua +++ b/net/http.lua @@ -13,7 +13,7 @@ local tonumber, tostring, pairs = tonumber, tostring, pairs; local print = function () end local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end }); -local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%x", c:byte()); end)); end +local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end module "http" diff --git a/prosody b/prosody index 3b95663f..98d15da2 100755 --- a/prosody +++ b/prosody @@ -115,7 +115,7 @@ function mkdir(path) path = path:gsub("/", path_separator); local x = io.popen("mkdir \""..path.."\" 2>&1"):read("*a"); end -function encode(s) return s and (s:gsub("%W", function (c) return string.format("%%%x", c:byte()); end)); end +function encode(s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end function mkdirs(host) if not _mkdir[host] then local host_dir = string.format("%s/%s", data_path, encode(host)); diff --git a/tools/ejabberd2prosody.lua b/tools/ejabberd2prosody.lua index 3c3ce945..858d78bb 100755 --- a/tools/ejabberd2prosody.lua +++ b/tools/ejabberd2prosody.lua @@ -37,7 +37,7 @@ function mkdir(path) --print("mkdir",path); local x = io.popen("mkdir "..path.." 2>&1"):read("*a"); end -function encode(s) return s and (s:gsub("%W", function (c) return string.format("%%%x", c:byte()); end)); end +function encode(s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end function getpath(username, host, datastore, ext) ext = ext or "dat"; if username then diff --git a/util/datamanager.lua b/util/datamanager.lua index e229de1c..45da17dd 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -44,7 +44,7 @@ do end encode = function (s) - return s and (s:gsub("%W", function (c) return format("%%%x", c:byte()); end)); + return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end end -- 2.30.2