Changeset

10019:c30c81176752

mod_storage_memory: Return error if 'before' or 'after' are not found (partial fix for #1325)
author Kim Alvefur <zash@zash.se>
date Tue, 05 Mar 2019 00:16:41 +0100
parents 10018:7408b9473729
children 10020:deb68066c7aa
files plugins/mod_storage_memory.lua
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_storage_memory.lua	Tue Mar 05 00:12:30 2019 +0100
+++ b/plugins/mod_storage_memory.lua	Tue Mar 05 00:16:41 2019 +0100
@@ -127,20 +127,30 @@
 		if query.reverse then
 			items:reverse();
 			if query.before then
+				local found = false;
 				for j = 1, #items do
 					if (items[j].key or tostring(j)) == query.before then
+						found = true;
 						i = j;
 						break;
 					end
 				end
+				if not found then
+					return nil, "item-not-found";
+				end
 			end
 		elseif query.after then
+			local found = false;
 			for j = 1, #items do
 				if (items[j].key or tostring(j)) == query.after then
+					found = true;
 					i = j;
 					break;
 				end
 			end
+			if not found then
+				return nil, "item-not-found";
+			end
 		end
 		if query.limit and #items - i > query.limit then
 			items[i+query.limit+1] = nil;