Software /
code /
prosody
Comparison
util/serialization.lua @ 9483:903e0cfd4cc9
util.serialization: Make check of prefix for optional hex encoding stricter
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 11 Oct 2018 22:59:26 +0200 |
parent | 9480:006a71a83e6a |
child | 9484:1d1541630c20 |
comparison
equal
deleted
inserted
replaced
9482:8791bfa3984a | 9483:903e0cfd4cc9 |
---|---|
215 | 215 |
216 local function serialize_string(s) | 216 local function serialize_string(s) |
217 return '"' .. s_gsub(s, "[%z\1-\31\"\'\\\127-\255]", string_escapes) .. '"'; | 217 return '"' .. s_gsub(s, "[%z\1-\31\"\'\\\127-\255]", string_escapes) .. '"'; |
218 end | 218 end |
219 | 219 |
220 if hex then | 220 if type(hex) == "string" then |
221 function types.string(s) | 221 function types.string(s) |
222 local esc = serialize_string(s); | 222 local esc = serialize_string(s); |
223 if #esc > (#s*2+2+#hex) then | 223 if #esc > (#s*2+2+#hex) then |
224 return hex .. '"' .. to_hex(s) .. '"'; | 224 return hex .. '"' .. to_hex(s) .. '"'; |
225 end | 225 end |