aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2008-11-21 05:02:53 +0000
committerMatthew Wild <mwild1@gmail.com>2008-11-21 05:02:53 +0000
commit48e7f5ea649e858d59afdf5331cd6f30364abe80 (patch)
tree6161fb672b507c10704f66975b484609aeab09d6 /util
parentc36a8743fed7cc3b75b3d71410f60f8ced4e65af (diff)
downloadprosody-48e7f5ea649e858d59afdf5331cd6f30364abe80.tar.gz
prosody-48e7f5ea649e858d59afdf5331cd6f30364abe80.zip
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Diffstat (limited to 'util')
-rw-r--r--util/jid.lua22
1 files changed, 15 insertions, 7 deletions
diff --git a/util/jid.lua b/util/jid.lua
index c9ea5b73..b35ddc82 100644
--- a/util/jid.lua
+++ b/util/jid.lua
@@ -1,20 +1,28 @@
local match = string.match;
-
+local tostring = tostring;
+local print = print
module "jid"
function split(jid)
if not jid then return; end
-- TODO verify JID, and return; if invalid
- local node = match(jid, "^([^@]+)@");
- local server = (node and match(jid, ".-@([^@/]+)")) or match(jid, "^([^@/]+)");
- local resource = match(jid, "/(.+)$");
- return node, server, resource;
+ local node, nodelen = match(jid, "^([^@]+)@()");
+ local host, hostlen = match(jid, "^([^@/]+)()", nodelen)
+ if node and not host then return nil, nil, nil; end
+ local resource = match(jid, "^/(.+)$", hostlen);
+ if (not host) or ((not resource) and #jid >= hostlen) then return nil, nil, nil; end
+ return node, host, resource;
end
function bare(jid)
local node, host = split(jid);
- return node.."@"..host;
+ if node and host then
+ return node.."@"..host;
+ elseif host then
+ return host;
+ end
+ return nil;
end
-return _M; \ No newline at end of file
+return _M;