Skip to content

Commit

Permalink
Update internal/exec/stack_processor_utils.go
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
milldr and coderabbitai[bot] authored Dec 27, 2024
1 parent 1beeb8a commit dd55c0f
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions internal/exec/stack_processor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1746,16 +1746,30 @@ func FindComponentDependenciesLegacy(
// resolveRelativePath checks if a path is relative to the current directory and if so,
// resolves it relative to the current file's directory
func resolveRelativePath(path string, currentFilePath string) string {
// Get the first element of the path
firstElement := filepath.Clean(strings.Split(path, string(filepath.Separator))[0])

// Check if the path starts with "." or ".."
if firstElement == "." || firstElement == ".." {
baseDir := filepath.Dir(currentFilePath)
result := filepath.ToSlash(filepath.Clean(filepath.Join(baseDir, path)))
return result
}
return path
if path == "" {
return path
}

// Normalize input path
path = filepath.FromSlash(path)
currentFilePath = filepath.FromSlash(currentFilePath)

// Get the first element of the path
firstElement := strings.Split(path, string(filepath.Separator))[0]

// Check if the path starts with "." or ".."
if firstElement == "." || firstElement == ".." {
baseDir := filepath.Dir(currentFilePath)
// Clean the path and convert to forward slashes
result := filepath.ToSlash(filepath.Clean(filepath.Join(baseDir, path)))

// Ensure the resolved path is still under the base directory
if !strings.HasPrefix(result, filepath.ToSlash(filepath.Clean(baseDir))) {
return path
}
return result
}
return path
}

// ProcessImportSection processes the `import` section in stack manifests
Expand Down

0 comments on commit dd55c0f

Please sign in to comment.