Software /
code /
prosody
Changeset
11056:0b0a42542456
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 28 Aug 2020 18:44:02 +0200 |
parents | 11055:5fb95410f89c |
children | 11057:13eee48071c8 |
files | util/jid.lua |
diffstat | 1 files changed, 6 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/util/jid.lua Fri Aug 28 18:43:37 2020 +0200 +++ b/util/jid.lua Fri Aug 28 18:44:02 2020 +0200 @@ -22,7 +22,11 @@ ["@"] = "\\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 @@ 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 {