From 31d6d1a42b9928648961f418dedfa778e60bc0ba Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 9 Sep 2019 22:15:04 +0200 Subject: util.jid: Add a 'strict' flag for jidprep calls --- util/jid.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'util/jid.lua') diff --git a/util/jid.lua b/util/jid.lua index ec31f180..1ddf33d4 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -45,20 +45,20 @@ local function bare(jid) return host; end -local function prepped_split(jid) +local function prepped_split(jid, strict) local node, host, resource = split(jid); if host and host ~= "." then if sub(host, -1, -1) == "." then -- Strip empty root label host = sub(host, 1, -2); end - host = nameprep(host); + host = nameprep(host, strict); if not host then return; end if node then - node = nodeprep(node); + node = nodeprep(node, strict); if not node then return; end end if resource then - resource = resourceprep(resource); + resource = resourceprep(resource, strict); if not resource then return; end end return node, host, resource; @@ -77,8 +77,8 @@ local function join(node, host, resource) return host; end -local function prep(jid) - local node, host, resource = prepped_split(jid); +local function prep(jid, strict) + local node, host, resource = prepped_split(jid, strict); return join(node, host, resource); end -- cgit v1.2.3 From b37e985f4871fd2816c315d74869b08a5eb17b9d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 28 Aug 2020 18:44:02 +0200 Subject: util.jid: Fix special escaping of '\' per XEP-0106 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From XEP-0106 §2. Requirements: > in certain circumstances, the escaping character itself ("\") might > also be escaped Later in §4.2 Address Transformation Algorithm it is stated that the backslash would only be escaped if it forms an escape sequence. Thus '\foo' is unaltered but '\20' must be escaped into '\5c20'. Thanks to lovetox and jonas’ for brining up. --- util/jid.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'util/jid.lua') diff --git a/util/jid.lua b/util/jid.lua index 1ddf33d4..a1180534 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -22,7 +22,11 @@ local escapes = { ["@"] = "\\40"; ["\\"] = "\\5c"; }; local unescapes = {}; -for k,v in pairs(escapes) do unescapes[v] = k; end +local backslash_escapes = {}; +for k,v in pairs(escapes) do + unescapes[v] = k; + backslash_escapes[v] = v:gsub("\\", escapes) +end local _ENV = nil; -- luacheck: std none @@ -107,7 +111,7 @@ local function resource(jid) return (select(3, split(jid))); end -local function escape(s) return s and (s:gsub(".", escapes)); end +local function escape(s) return s and (s:gsub("\\%x%x", backslash_escapes):gsub("[\"&'/:<>@ ]", escapes)); end local function unescape(s) return s and (s:gsub("\\%x%x", unescapes)); end return { -- cgit v1.2.3