@@ -28,7 +28,7 @@ import (
2828type ResetProcessor struct {
2929 target interface {}
3030 paths []tree.Path
31- visitedNodes map [* yaml.Node ]bool
31+ visitedNodes map [* yaml.Node ]string
3232}
3333
3434// UnmarshalYAML implement yaml.Unmarshaler
@@ -43,23 +43,27 @@ func (p *ResetProcessor) UnmarshalYAML(value *yaml.Node) error {
4343
4444// resolveReset detects `!reset` tag being set on yaml nodes and record position in the yaml tree
4545func (p * ResetProcessor ) resolveReset (node * yaml.Node , path tree.Path ) (* yaml.Node , error ) {
46+ pathStr := path .String ()
4647 // If the path contains "<<", removing the "<<" element and merging the path
47- if strings .Contains (path . String () , ".<<" ) {
48- path = tree .NewPath (strings .Replace (path . String () , ".<<" , "" , 1 ))
48+ if strings .Contains (pathStr , ".<<" ) {
49+ path = tree .NewPath (strings .Replace (pathStr , ".<<" , "" , 1 ))
4950 }
5051
5152 // Check for cycle
5253 if p .visitedNodes == nil {
53- p .visitedNodes = make (map [* yaml.Node ]bool )
54+ p .visitedNodes = make (map [* yaml.Node ]string )
5455 }
5556
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 ())
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+ }
5963 }
6064
6165 // Mark the current node as visited
62- p .visitedNodes [node ] = true
66+ p .visitedNodes [node ] = pathStr
6367
6468 // If the node is an alias, We need to process the alias field in order to consider the !override and !reset tags
6569 if node .Kind == yaml .AliasNode {
0 commit comments