aboutsummaryrefslogtreecommitdiffstats
path: root/util/datamanager.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-10-08 18:34:57 +0200
committerKim Alvefur <zash@zash.se>2017-10-08 18:34:57 +0200
commit2572082717a2bd675cfed0c18d362d56b90346c1 (patch)
tree57174b115675351966b160c493802350e1d24207 /util/datamanager.lua
parent1245e980da35efdaee4a2ae9ab30435a7dd78e6e (diff)
downloadprosody-2572082717a2bd675cfed0c18d362d56b90346c1.tar.gz
prosody-2572082717a2bd675cfed0c18d362d56b90346c1.zip
util.datamanager: Encode the 'store' path component, preserving underscores
Diffstat (limited to 'util/datamanager.lua')
-rw-r--r--util/datamanager.lua9
1 files changed, 8 insertions, 1 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua
index bd8fb7bb..bd402b51 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -42,7 +42,7 @@ end);
local _ENV = nil;
---- utils -----
-local encode, decode;
+local encode, decode, store_encode;
do
local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber(k, 16)); return t[k]; end });
@@ -53,6 +53,12 @@ do
encode = function (s)
return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end));
end
+
+ -- Special encode function for store names, which historically were unencoded.
+ -- All currently known stores use a-z and underscore, so this one preserves underscores.
+ store_encode = function (s)
+ return s and (s:gsub("[^_%w]", function (c) return format("%%%02x", c:byte()); end));
+ end
end
if not atomic_append then
@@ -119,6 +125,7 @@ local function getpath(username, host, datastore, ext, create)
ext = ext or "dat";
host = (host and encode(host)) or "_global";
username = username and encode(username);
+ datastore = store_encode(datastore);
if username then
if create then mkdir(mkdir(mkdir(data_path).."/"..host).."/"..datastore); end
return format("%s/%s/%s/%s.%s", data_path, host, datastore, username, ext);