@@ -26,13 +26,15 @@ import (
2626)
2727
2828type ResetProcessor struct {
29- target interface {}
30- paths []tree.Path
29+ target interface {}
30+ paths []tree.Path
31+ visitedNodes map [* yaml.Node ]bool
3132}
3233
3334// UnmarshalYAML implement yaml.Unmarshaler
3435func (p * ResetProcessor ) UnmarshalYAML (value * yaml.Node ) error {
3536 resolved , err := p .resolveReset (value , tree .NewPath ())
37+ p .visitedNodes = nil
3638 if err != nil {
3739 return err
3840 }
@@ -45,6 +47,20 @@ func (p *ResetProcessor) resolveReset(node *yaml.Node, path tree.Path) (*yaml.No
4547 if strings .Contains (path .String (), ".<<" ) {
4648 path = tree .NewPath (strings .Replace (path .String (), ".<<" , "" , 1 ))
4749 }
50+
51+ // Check for cycle
52+ if p .visitedNodes == nil {
53+ p .visitedNodes = make (map [* yaml.Node ]bool )
54+ }
55+
56+ // Check if the current node has been visited before (cycle detection)
57+ if p .visitedNodes [node ] {
58+ return nil , fmt .Errorf ("cycle detected at path: %s" , path .String ())
59+ }
60+
61+ // Mark the current node as visited
62+ p .visitedNodes [node ] = true
63+
4864 // If the node is an alias, We need to process the alias field in order to consider the !override and !reset tags
4965 if node .Kind == yaml .AliasNode {
5066 return p .resolveReset (node .Alias , path )
0 commit comments