Mercurial > prosody-hg
comparison plugins/mod_storage_internal.lua @ 10018:7408b9473729
mod_storage_internal: 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:12:30 +0100 |
| parents | 55f5588d71c6 |
| children | 4a0d990253a0 |
comparison
equal
deleted
inserted
replaced
| 10017:994cccebb597 | 10018:7408b9473729 |
|---|---|
| 159 count = #items; | 159 count = #items; |
| 160 end | 160 end |
| 161 if query.reverse then | 161 if query.reverse then |
| 162 items:reverse(); | 162 items:reverse(); |
| 163 if query.before then | 163 if query.before then |
| 164 local found = false; | |
| 164 for j = 1, #items do | 165 for j = 1, #items do |
| 165 if (items[j].key or tostring(j)) == query.before then | 166 if (items[j].key or tostring(j)) == query.before then |
| 167 found = true; | |
| 166 i = j; | 168 i = j; |
| 167 break; | 169 break; |
| 168 end | 170 end |
| 169 end | 171 end |
| 172 if not found then | |
| 173 return nil, "item-not-found"; | |
| 174 end | |
| 170 end | 175 end |
| 171 elseif query.after then | 176 elseif query.after then |
| 177 local found = false; | |
| 172 for j = 1, #items do | 178 for j = 1, #items do |
| 173 if (items[j].key or tostring(j)) == query.after then | 179 if (items[j].key or tostring(j)) == query.after then |
| 180 found = true; | |
| 174 i = j; | 181 i = j; |
| 175 break; | 182 break; |
| 176 end | 183 end |
| 184 end | |
| 185 if not found then | |
| 186 return nil, "item-not-found"; | |
| 177 end | 187 end |
| 178 end | 188 end |
| 179 if query.limit and #items - i > query.limit then | 189 if query.limit and #items - i > query.limit then |
| 180 items[i+query.limit+1] = nil; | 190 items[i+query.limit+1] = nil; |
| 181 end | 191 end |
