mod_storage_memory: Fix overwriting old keys
authorKim Alvefur <zash@zash.se>
Sun, 21 Oct 2018 18:00:46 +0200
changeset 9537 b301f7edf346
parent 9536 00a8e627854e
child 9538 c1befd1c886d
mod_storage_memory: Fix overwriting old keys Test fixed is: spec/core_storagemanager_spec.lua:309: Expected objects to be equal.
plugins/mod_storage_memory.lua
--- a/plugins/mod_storage_memory.lua	Sun Oct 21 17:58:50 2018 +0200
+++ b/plugins/mod_storage_memory.lua	Sun Oct 21 18:00:46 2018 +0200
@@ -53,7 +53,6 @@
 		a = {};
 		self.store[username or NULL] = a;
 	end
-	local i = #a+1;
 	local v = { key = key, when = when, with = with, value = value };
 	if not key then
 		key = tostring(a):match"%x+$"..tostring(v):match"%x+$";
@@ -62,6 +61,7 @@
 	if a[key] then
 		table.remove(a, a[key]);
 	end
+	local i = #a+1;
 	a[i] = v;
 	a[key] = i;
 	return key;