From c36a8743fed7cc3b75b3d71410f60f8ced4e65af Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 20 Nov 2008 23:28:16 +0000 Subject: Add jid.bare() helper function --- util/jid.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'util/jid.lua') diff --git a/util/jid.lua b/util/jid.lua index b1e4131d..c9ea5b73 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -12,4 +12,9 @@ function split(jid) return node, server, resource; end +function bare(jid) + local node, host = split(jid); + return node.."@"..host; +end + return _M; \ No newline at end of file -- cgit v1.2.3 From 48e7f5ea649e858d59afdf5331cd6f30364abe80 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 21 Nov 2008 05:02:53 +0000 Subject: Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs --- util/jid.lua | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'util/jid.lua') 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; -- cgit v1.2.3 From 430180dafb4f6f839aa04871ed316ef6bb6f3578 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 21 Nov 2008 05:06:01 +0000 Subject: Remove some declarations I added while debugging --- util/jid.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'util/jid.lua') diff --git a/util/jid.lua b/util/jid.lua index b35ddc82..aad579e9 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -1,7 +1,6 @@ local match = string.match; -local tostring = tostring; -local print = print + module "jid" function split(jid) -- cgit v1.2.3 From 9122ff00399f77e31b902ac431288341dba70e64 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 21 Nov 2008 05:06:35 +0000 Subject: Remove old TODO --- util/jid.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'util/jid.lua') diff --git a/util/jid.lua b/util/jid.lua index aad579e9..efa79b38 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -5,7 +5,6 @@ module "jid" function split(jid) if not jid then return; end - -- TODO verify JID, and return; if invalid local node, nodelen = match(jid, "^([^@]+)@()"); local host, hostlen = match(jid, "^([^@/]+)()", nodelen) if node and not host then return nil, nil, nil; end -- cgit v1.2.3 From e550dff27204b473ab426807f918672951d17505 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 21 Nov 2008 05:07:41 +0000 Subject: Better names for variables --- util/jid.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'util/jid.lua') diff --git a/util/jid.lua b/util/jid.lua index efa79b38..2e40a338 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -5,11 +5,11 @@ module "jid" function split(jid) if not jid then return; end - local node, nodelen = match(jid, "^([^@]+)@()"); - local host, hostlen = match(jid, "^([^@/]+)()", nodelen) + local node, nodepos = match(jid, "^([^@]+)@()"); + local host, hostpos = match(jid, "^([^@/]+)()", nodepos) 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 + local resource = match(jid, "^/(.+)$", hostpos); + if (not host) or ((not resource) and #jid >= hostpos) then return nil, nil, nil; end return node, host, resource; end -- cgit v1.2.3 From d2db971613c66f265f63a9c2543ad2cffab65dcb Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 22 Nov 2008 22:37:44 +0500 Subject: Removed useless check --- util/jid.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'util/jid.lua') diff --git a/util/jid.lua b/util/jid.lua index 2e40a338..065f176f 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -17,10 +17,8 @@ function bare(jid) local node, host = split(jid); if node and host then return node.."@"..host; - elseif host then - return host; end - return nil; + return host; end return _M; -- cgit v1.2.3