Skip to content

Commit 0f0b419

Browse files
committed
chore: harden v2 helper edges
1 parent c731d18 commit 0f0b419

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

query/v2/query.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func ExactDepth(depth int64) TraversalDepth {
7878
return newTraversalDepth(depthBound, depthBound)
7979
}
8080

81+
// Accessors return fresh variables; compare symbols rather than pointer identity.
8182
func (s runtimeIdentifiers) Path() *cypher.Variable {
8283
return cypher.NewVariableWithSymbol(s.path)
8384
}
@@ -731,6 +732,7 @@ type QueryBuilder interface {
731732
Where(constraints ...cypher.SyntaxNode) QueryBuilder
732733
OrderBy(sortItems ...any) QueryBuilder
733734
Skip(offset int) QueryBuilder
735+
// Limit accepts zero, which renders LIMIT 0 and returns an empty result set.
734736
Limit(limit int) QueryBuilder
735737
Return(projections ...any) QueryBuilder
736738
ReturnDistinct(projections ...any) QueryBuilder
@@ -898,6 +900,7 @@ func (s *builder) appendDeleteItems(detach bool, items ...cypher.Expression) {
898900
return
899901
}
900902

903+
// Consecutive deletes share one clause; any node delete makes the whole clause DETACH DELETE.
901904
lastClauseIdx := len(s.updatingClauses) - 1
902905
if lastClauseIdx >= 0 && s.updatingClauses[lastClauseIdx].kind == updatingClauseDelete {
903906
s.updatingClauses[lastClauseIdx].detach = s.updatingClauses[lastClauseIdx].detach || detach

query/v2/util.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,20 @@ func (s *identifierSet) Clone() *identifierSet {
692692
}
693693

694694
func (s *identifierSet) Or(other *identifierSet) {
695+
if s == nil || other == nil {
696+
return
697+
}
698+
695699
for otherIdentifier := range other.identifiers {
696700
s.identifiers[otherIdentifier] = struct{}{}
697701
}
698702
}
699703

700704
func (s *identifierSet) Remove(other *identifierSet) {
705+
if s == nil || other == nil {
706+
return
707+
}
708+
701709
for otherIdentifier := range other.identifiers {
702710
delete(s.identifiers, otherIdentifier)
703711
}

query/v2/util_internal_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package v2
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestIdentifierSetOrAndRemoveNilSafe(t *testing.T) {
10+
var nilSet *identifierSet
11+
12+
nilSet.Or(newIdentifierSet("ignored"))
13+
nilSet.Remove(newIdentifierSet("ignored"))
14+
15+
set := newIdentifierSet("kept")
16+
set.Or(nil)
17+
set.Remove(nil)
18+
19+
require.True(t, set.Contains("kept"))
20+
}

0 commit comments

Comments
 (0)