Skip to content

Commit

Permalink
fix: clone parent map for MergeMaps function
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen committed Jan 19, 2024
1 parent f7ec709 commit 710b6cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pkg/java/pom/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,11 @@ func (p *parser) resolveDepManagement(props map[string]string, depManagement []p

// We need to recursively check all nested depManagements,
// so that we don't miss dependencies on nested depManagements with `Import` scope.
result.dependencyManagement = p.resolveDepManagement(utils.MergeMaps(result.properties, props), result.dependencyManagement)
newProps := utils.MergeMaps(props, result.properties)
result.dependencyManagement = p.resolveDepManagement(newProps, result.dependencyManagement)
for k, dd := range result.dependencyManagement {
// Evaluate variables and overwrite dependencyManagement
result.dependencyManagement[k] = dd.Resolve(result.properties, nil, nil)
result.dependencyManagement[k] = dd.Resolve(newProps, nil, nil)
}
newDepManagement = p.mergeDependencyManagements(newDepManagement, result.dependencyManagement)
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ func MergeMaps(parent, child map[string]string) map[string]string {
if parent == nil {
return child
}
// Clone parent map to avoid shadow overwrite
newParent := maps.Clone(parent)
for k, v := range child {
parent[k] = v
newParent[k] = v
}
return parent
return newParent
}

func PackageID(name, version string) string {
Expand Down

0 comments on commit 710b6cc

Please sign in to comment.