diff options
author | Kim Alvefur <zash@zash.se> | 2020-08-28 18:44:02 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2020-08-28 18:44:02 +0200 |
commit | ace2ee1b3b34a9e122367abe945298c4a7e6865f (patch) | |
tree | ff95ee34f21e29c17a6f24025c7f603c633ac102 /util/jid.lua | |
parent | f7cdeb54fdc288dd548f0ab2020a2440c0332f97 (diff) | |
download | prosody-ace2ee1b3b34a9e122367abe945298c4a7e6865f.tar.gz prosody-ace2ee1b3b34a9e122367abe945298c4a7e6865f.zip |
util.jid: Fix special escaping of '\' per XEP-0106
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.
Diffstat (limited to 'util/jid.lua')
-rw-r--r-- | util/jid.lua | 8 |
1 files changed, 6 insertions, 2 deletions
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 { |