aboutsummaryrefslogtreecommitdiffstats
path: root/util/jid.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2011-11-01 23:41:32 +0500
committerWaqas Hussain <waqas20@gmail.com>2011-11-01 23:41:32 +0500
commit9141da8948020f2e3aecc479cb820c4741694e7b (patch)
tree01792e64451ef9fed3e27e27c5a2a8be16d39d1b /util/jid.lua
parentf6ea411e763a8817a808df9ba3f5b31f3f76aa28 (diff)
downloadprosody-9141da8948020f2e3aecc479cb820c4741694e7b.tar.gz
prosody-9141da8948020f2e3aecc479cb820c4741694e7b.zip
util.jid: Added escape() and unescape().
Diffstat (limited to 'util/jid.lua')
-rw-r--r--util/jid.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/util/jid.lua b/util/jid.lua
index 069817c6..4c4371d8 100644
--- a/util/jid.lua
+++ b/util/jid.lua
@@ -13,6 +13,16 @@ local nodeprep = require "util.encodings".stringprep.nodeprep;
local nameprep = require "util.encodings".stringprep.nameprep;
local resourceprep = require "util.encodings".stringprep.resourceprep;
+local escapes = {
+ [" "] = "\\20"; ['"'] = "\\22";
+ ["&"] = "\\26"; ["'"] = "\\27";
+ ["/"] = "\\2f"; [":"] = "\\3a";
+ ["<"] = "\\3c"; [">"] = "\\3e";
+ ["@"] = "\\40"; ["\\"] = "\\5c";
+};
+local unescapes = {};
+for k,v in pairs(escapes) do unescapes[v] = k; end
+
module "jid"
local function _split(jid)
@@ -91,4 +101,7 @@ function compare(jid, acl)
return false
end
+function escape(s) return s and (s:gsub(".", escapes)); end
+function unescape(s) return s and (s:gsub("\\%x%x", unescapes)); end
+
return _M;