Restore the pre 23.1 behavour of lists:sublist/3

As we depend on it to detect an out of range request and return an HTTP
400 response.
This commit is contained in:
kjnilsson 2020-09-30 14:03:28 +01:00
parent 44c34a4b21
commit 323834a7fd
1 changed files with 6 additions and 1 deletions

View File

@ -610,7 +610,7 @@ range_filter(List, RP = #pagination{page = PageNum, page_size = PageSize},
TotalElements) ->
Offset = (PageNum - 1) * PageSize + 1,
try
range_response(lists:sublist(List, Offset, PageSize), RP, List,
range_response(sublist(List, Offset, PageSize), RP, List,
TotalElements)
catch
error:function_clause ->
@ -1203,3 +1203,8 @@ catch_no_such_user_or_vhost(Fun, Replacement) ->
catch throw:{error, {E, _}} when E =:= no_such_user; E =:= no_such_vhost ->
Replacement()
end.
%% this retains the old, buggy, pre 23.1 behavour of lists:sublist/3 where an
%% error is thrown when the request is out of range
sublist(List, S, L) when is_integer(L), L >= 0 ->
lists:sublist(lists:nthtail(S-1, List), L).