Skip to content
This repository has been archived by the owner on Mar 18, 2021. It is now read-only.

Commit

Permalink
Prevent Query.where.oneOf from allowing null or empty set (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjoeconway authored Aug 29, 2018
1 parent 3ddcc9a commit 965e32f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions aqueduct/lib/src/db/query/matcher_expression.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ class QueryExpression<T, InstanceType> {
/// var query = new Query<Employee>()
/// ..where((e) => e.department).oneOf(["Engineering", "HR"]);
QueryExpressionJunction<T, InstanceType> oneOf(Iterable<T> values) {
if (values?.isEmpty ?? true) {
throw ArgumentError("'Query.where.oneOf' cannot be the empty set or null.");
}
expression = SetMembershipExpression(values.toList());

return _createJunction();
Expand Down
9 changes: 8 additions & 1 deletion aqueduct/test/db/postgresql/matcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void main() {
});
});

test("whereIn matcher", () async {
test("oneOf matcher", () async {
var q = Query<TestModel>(context)..where((o) => o.id).oneOf([1, 2]);
var results = await q.fetch();
expect(results.length, 2);
Expand All @@ -202,6 +202,13 @@ void main() {
expect(results.length, 4);
expect(results.any((t) => t.id == 1), false);
expect(results.any((t) => t.id == 2), false);

try {
Query<TestModel>(context).where((o) => o.id).not.oneOf([]);
fail('unreachable');
} on ArgumentError catch (e) {
expect(e.toString(), contains("oneOf' cannot be the empty set or null"));
}
});

test("whereBetween matcher", () async {
Expand Down

0 comments on commit 965e32f

Please sign in to comment.