@@ -49,24 +49,12 @@ func (p *ResetProcessor) resolveReset(node *yaml.Node, path tree.Path) (*yaml.No
49
49
path = tree .NewPath (strings .Replace (pathStr , ".<<" , "" , 1 ))
50
50
}
51
51
52
- // Check for cycle
53
- if p .visitedNodes == nil {
54
- p .visitedNodes = make (map [* yaml.Node ]string )
55
- }
56
-
57
- // Check for cycle by seeing if the node has already been visited at this path
58
- if previousPath , found := p .visitedNodes [node ]; found {
59
- // If the current node has been visited, we have a cycle if the previous path is a prefix
60
- if strings .HasPrefix (pathStr , previousPath ) {
61
- return nil , fmt .Errorf ("cycle detected at path: %s" , pathStr )
62
- }
63
- }
64
-
65
- // Mark the current node as visited
66
- p .visitedNodes [node ] = pathStr + "."
67
-
68
52
// If the node is an alias, We need to process the alias field in order to consider the !override and !reset tags
69
53
if node .Kind == yaml .AliasNode {
54
+ if err := p .checkForCycle (node .Alias , path ); err != nil {
55
+ return nil , err
56
+ }
57
+
70
58
return p .resolveReset (node .Alias , path )
71
59
}
72
60
@@ -154,3 +142,22 @@ func (p *ResetProcessor) applyNullOverrides(target any, path tree.Path) error {
154
142
}
155
143
return nil
156
144
}
145
+
146
+ func (p * ResetProcessor ) checkForCycle (node * yaml.Node , path tree.Path ) error {
147
+ if p .visitedNodes == nil {
148
+ p .visitedNodes = make (map [* yaml.Node ]string )
149
+ }
150
+
151
+ // Check for cycle by seeing if the node has already been visited at this path
152
+ if previousPath , found := p .visitedNodes [node ]; found {
153
+ // If the current node has been visited, we have a cycle if the previous path is a prefix
154
+ if strings .HasPrefix (path .String (), strings .TrimRight (previousPath , "<<" )) {
155
+ return fmt .Errorf ("cycle detected at path: %s" , previousPath )
156
+ }
157
+ }
158
+
159
+ // Mark the current node as visited
160
+ p .visitedNodes [node ] = path .String ()
161
+
162
+ return nil
163
+ }
0 commit comments