X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fjid.lua;h=27afab3e275e2de573e8b18f6211a7fbebfb5476;hb=f6b3f550857678d676b31c5338f4bc6a93df1339;hp=0d9a864fa3b1d8a4faa5e747a96c30a1c47e20a9;hpb=1b01b4fe53c7e81fc6911a63031713166f0917bf;p=prosody.git diff --git a/util/jid.lua b/util/jid.lua index 0d9a864f..27afab3e 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -8,7 +8,7 @@ -local match = string.match; +local match, sub = string.match, string.sub; local nodeprep = require "util.encodings".stringprep.nodeprep; local nameprep = require "util.encodings".stringprep.nameprep; local resourceprep = require "util.encodings".stringprep.resourceprep; @@ -37,16 +37,15 @@ end split = _split; function bare(jid) - local node, host = _split(jid); - if node and host then - return node.."@"..host; - end - return host; + return jid and match(jid, "^[^/]+"); end local function _prepped_split(jid) local node, host, resource = _split(jid); if host then + if sub(host, -1, -1) == "." then -- Strip empty root label + host = sub(host, 1, -2); + end host = nameprep(host); if not host then return; end if node then @@ -62,30 +61,22 @@ local function _prepped_split(jid) end prepped_split = _prepped_split; -function prep(jid) - local node, host, resource = _prepped_split(jid); - if host then - if node then - host = node .. "@" .. host; - end - if resource then - host = host .. "/" .. resource; - end - end - return host; -end - -function join(node, host, resource) - if node and host and resource then +local function _join(node, host, resource) + if not host then return end + if node and resource then return node.."@"..host.."/"..resource; - elseif node and host then + elseif node then return node.."@"..host; - elseif host and resource then + elseif resource then return host.."/"..resource; - elseif host then - return host; end - return nil; -- Invalid JID + return host; +end +join = _join; + +function prep(jid) + local node, host, resource = _prepped_split(jid); + return _join(node, host, resource); end function compare(jid, acl)