From 8aabc3b56c2dee60cc275f51c922cda0a7e30970 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 7 Aug 2014 17:20:51 +0200 Subject: util.jid: Return early in join on invalid jids --- util/jid.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'util') diff --git a/util/jid.lua b/util/jid.lua index 08e63335..5db3d1f0 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -79,16 +79,15 @@ function prep(jid) end function join(node, host, resource) - if node and host and resource then + if not host then return end -- Invalid JID + 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 function compare(jid, acl) -- cgit v1.2.3 From d68e3b56200c4c208e38d75b3396ae8c9de27423 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 7 Aug 2014 17:35:11 +0200 Subject: util.jid: Use existing join function in jid.prep --- util/jid.lua | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'util') diff --git a/util/jid.lua b/util/jid.lua index 5db3d1f0..14d8f2b4 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -65,21 +65,8 @@ 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 not host then return end -- Invalid JID +local function _join(node, host, resource) + if not host then return end if node and resource then return node.."@"..host.."/"..resource; elseif node then @@ -89,6 +76,12 @@ function join(node, host, resource) end 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) -- compare jid to single acl rule -- cgit v1.2.3 From 9875580ca905a10e26448509a1f46f4a270a8e61 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 7 Aug 2014 17:43:28 +0200 Subject: util.jid: Optimize bare --- util/jid.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'util') diff --git a/util/jid.lua b/util/jid.lua index 14d8f2b4..27afab3e 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -37,11 +37,7 @@ 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) -- cgit v1.2.3