# HG changeset patch # User Kim Alvefur # Date 1507480497 -7200 # Node ID 756a2a00e7e7e733f988b1b0a44be3d40c811ea9 # Parent dd9fa511494ac984d076f2c53f38ecf41b365da5 util.datamanager: Encode the 'store' path component, preserving underscores diff -r dd9fa511494a -r 756a2a00e7e7 util/datamanager.lua --- a/util/datamanager.lua Sun Oct 08 01:28:32 2017 +0200 +++ b/util/datamanager.lua Sun Oct 08 18:34:57 2017 +0200 @@ -42,7 +42,7 @@ 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 @@ 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 @@ 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);