Skip to content

Commit 7b11102

Browse files
committed
fix(query/v2): reject empty logical helpers
1 parent cd2a4ba commit 7b11102

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

query/v2/query.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ func valueExpression(value any) cypher.Expression {
214214
}
215215

216216
func joinedExpressionList(operator cypher.Operator, operands []cypher.SyntaxNode) cypher.SyntaxNode {
217+
if len(operands) == 0 {
218+
return invalidExpression(fmt.Errorf("%s requires at least one operand", operator))
219+
}
220+
217221
expressionList := &cypher.Comparison{}
218222

219223
if len(operands) > 0 {

query/v2/query_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ func TestMixedNodeAndRelationshipIdentifiersReturnError(t *testing.T) {
250250
require.ErrorContains(t, err, "query mixes node and relationship query identifiers")
251251
}
252252

253+
func TestEmptyLogicalHelpersReturnBuildErrors(t *testing.T) {
254+
_, err := v2.New().Where(v2.And()).Return(v2.Node()).Build()
255+
require.ErrorContains(t, err, "and requires at least one operand")
256+
257+
_, err = v2.New().Where(v2.Or()).Return(v2.Node()).Build()
258+
require.ErrorContains(t, err, "or requires at least one operand")
259+
}
260+
253261
func TestInvalidExplicitRelationshipPatternDirectionReturnsError(t *testing.T) {
254262
_, err := v2.New().Create(
255263
v2.RelationshipPattern(graph.StringKind("Edge"), nil, graph.DirectionBoth),

0 commit comments

Comments
 (0)