Software /
code /
prosody
Comparison
plugins/mod_storage_memory.lua @ 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 |
parent | 9997:7c4631d7b6fb |
child | 10023:f6959fe81a1d |
comparison
equal
deleted
inserted
replaced
10018:7408b9473729 | 10019:c30c81176752 |
---|---|
125 count = #items; | 125 count = #items; |
126 end | 126 end |
127 if query.reverse then | 127 if query.reverse then |
128 items:reverse(); | 128 items:reverse(); |
129 if query.before then | 129 if query.before then |
130 local found = false; | |
130 for j = 1, #items do | 131 for j = 1, #items do |
131 if (items[j].key or tostring(j)) == query.before then | 132 if (items[j].key or tostring(j)) == query.before then |
133 found = true; | |
132 i = j; | 134 i = j; |
133 break; | 135 break; |
134 end | 136 end |
135 end | 137 end |
138 if not found then | |
139 return nil, "item-not-found"; | |
140 end | |
136 end | 141 end |
137 elseif query.after then | 142 elseif query.after then |
143 local found = false; | |
138 for j = 1, #items do | 144 for j = 1, #items do |
139 if (items[j].key or tostring(j)) == query.after then | 145 if (items[j].key or tostring(j)) == query.after then |
146 found = true; | |
140 i = j; | 147 i = j; |
141 break; | 148 break; |
142 end | 149 end |
150 end | |
151 if not found then | |
152 return nil, "item-not-found"; | |
143 end | 153 end |
144 end | 154 end |
145 if query.limit and #items - i > query.limit then | 155 if query.limit and #items - i > query.limit then |
146 items[i+query.limit+1] = nil; | 156 items[i+query.limit+1] = nil; |
147 end | 157 end |