Software /
code /
prosody
Changeset
4407:f78c6f5fa090
util.jid: Added escape() and unescape().
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Tue, 01 Nov 2011 23:41:32 +0500 |
parents | 4406:424e14d3f99b |
children | 4408:21881619a394 |
files | util/jid.lua |
diffstat | 1 files changed, 13 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/util/jid.lua Wed Oct 26 18:58:01 2011 -0400 +++ b/util/jid.lua Tue Nov 01 23:41:32 2011 +0500 @@ -13,6 +13,16 @@ 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 @@ 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;