1
0
mirror of synced 2026-02-13 13:06:56 +00:00

fix: normalize paths to prevent concatenation on Windows

Fixes #5673

On Windows, when using absolute paths like C:\path\to\dir,
the path could be incorrectly concatenated, resulting in:
C:\working\dir\C:\path\to\dir\file

This fix applies filepath.Abs() and filepath.Clean() to normalize
the path before using it, ensuring absolute paths are handled
correctly on all platforms.

Changes:
- Apply filepath.Abs() to convert relative paths to absolute
- Apply filepath.Clean() to remove redundant separators and resolve ..
- Add tests for absolute paths, complex paths with .., and paths
  with redundant separators to verify normalization works correctly

The tests use actual 'flux build kustomization' commands with:
1. Absolute paths (prevents concatenation bugs)
2. Paths with parent directory (..) references
3. Paths with redundant separators (//)

All tests verify the command produces correct output, ensuring
the path normalization fix works as expected.

Signed-off-by: Sibasis Padhi <sibasis.padhi@gmail.com>
This commit is contained in:
Sibasis Padhi
2026-01-13 10:25:59 -06:00
parent f2f7d59577
commit 7dd9fde7ce
2 changed files with 70 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ import (
"fmt"
"os"
"os/signal"
"path/filepath"
"github.com/spf13/cobra"
@@ -97,6 +98,13 @@ func buildKsCmdRun(cmd *cobra.Command, args []string) (err error) {
return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
}
// Normalize the path to handle Windows absolute and relative paths correctly
buildKsArgs.path, err = filepath.Abs(buildKsArgs.path)
if err != nil {
return fmt.Errorf("failed to resolve absolute path: %w", err)
}
buildKsArgs.path = filepath.Clean(buildKsArgs.path)
if fs, err := os.Stat(buildKsArgs.path); err != nil || !fs.IsDir() {
return fmt.Errorf("invalid resource path %q", buildKsArgs.path)
}