@@ -26,13 +26,15 @@ import (
26
26
)
27
27
28
28
type ResetProcessor struct {
29
- target interface {}
30
- paths []tree.Path
29
+ target interface {}
30
+ paths []tree.Path
31
+ visitedNodes map [* yaml.Node ]bool
31
32
}
32
33
33
34
// UnmarshalYAML implement yaml.Unmarshaler
34
35
func (p * ResetProcessor ) UnmarshalYAML (value * yaml.Node ) error {
35
36
resolved , err := p .resolveReset (value , tree .NewPath ())
37
+ p .visitedNodes = nil
36
38
if err != nil {
37
39
return err
38
40
}
@@ -45,6 +47,20 @@ func (p *ResetProcessor) resolveReset(node *yaml.Node, path tree.Path) (*yaml.No
45
47
if strings .Contains (path .String (), ".<<" ) {
46
48
path = tree .NewPath (strings .Replace (path .String (), ".<<" , "" , 1 ))
47
49
}
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
+
48
64
// If the node is an alias, We need to process the alias field in order to consider the !override and !reset tags
49
65
if node .Kind == yaml .AliasNode {
50
66
return p .resolveReset (node .Alias , path )
0 commit comments