You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2020/08/04 20:29:41 UTC
[couchdb] 01/01: Validate the result from collate_fun
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch prototype/fdb-layer-ebtree-collate-validate
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 44564eb7ef9ba2051c96520d8180d39fb35f2e1d
Author: Robert Newson <rn...@apache.org>
AuthorDate: Tue Aug 4 21:28:58 2020 +0100
Validate the result from collate_fun
---
src/ebtree/src/ebtree.erl | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/ebtree/src/ebtree.erl b/src/ebtree/src/ebtree.erl
index bae0ff3..36d3c47 100644
--- a/src/ebtree/src/ebtree.erl
+++ b/src/ebtree/src/ebtree.erl
@@ -918,7 +918,13 @@ collate(#tree{} = _Tree, _A, ?MAX) ->
collate(#tree{} = Tree, A, B) ->
#tree{collate_fun = CollateFun} = Tree,
- CollateFun(A, B).
+ Result = CollateFun(A, B),
+ case lists:member(Result, [lt, eq, gt]) of
+ true ->
+ Result;
+ false ->
+ throw(invalid_collation_result)
+ end.
collate(#tree{} = Tree, A, B, Allowed) ->
@@ -1090,6 +1096,11 @@ collation_fun_test_() ->
].
+collate_validation_test() ->
+ Tree = #tree{collate_fun = fun(_A, _B) -> foo end},
+ ?assertThrow(invalid_collation_result, collate(Tree, 1, 2)).
+
+
lookup_test() ->
Db = erlfdb_util:get_test_db([empty]),
Tree = open(Db, <<1,2,3>>, 4),