mirror of
https://github.com/bjc/prosody.git
synced 2025-04-06 06:37:37 +03:00
util.jid: Added escape() and unescape().
This commit is contained in:
parent
7b90137fe8
commit
6a6318f924
1 changed files with 13 additions and 0 deletions
13
util/jid.lua
13
util/jid.lua
|
@ -13,6 +13,16 @@ local nodeprep = require "util.encodings".stringprep.nodeprep;
|
||||||
local nameprep = require "util.encodings".stringprep.nameprep;
|
local nameprep = require "util.encodings".stringprep.nameprep;
|
||||||
local resourceprep = require "util.encodings".stringprep.resourceprep;
|
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"
|
module "jid"
|
||||||
|
|
||||||
local function _split(jid)
|
local function _split(jid)
|
||||||
|
@ -91,4 +101,7 @@ function compare(jid, acl)
|
||||||
return false
|
return false
|
||||||
end
|
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;
|
return _M;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue