Skip to content

Commit

Permalink
🐛 make sure file paths don't contain bad characters:
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <[email protected]>
  • Loading branch information
pranavgaikwad committed Jan 15, 2025
1 parent f1169df commit b6b0f12
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"sync"
"text/template"
Expand Down Expand Up @@ -396,8 +397,11 @@ func explode(ctx context.Context, log logr.Logger, archivePath, projectPath stri
}
// any other files, move to java project as-is
default:
baseName := strings.ToValidUTF8(f.Name, "_")
re := regexp.MustCompile(`[^\w\-\.\\/]+`)
baseName = re.ReplaceAllString(baseName, "_")
destPath := filepath.Join(
projectPath, strings.Replace(filepath.Base(archivePath), ".", "-", -1)+"-exploded", f.Name)
projectPath, strings.Replace(filepath.Base(archivePath), ".", "-", -1)+"-exploded", baseName)
if err := os.MkdirAll(filepath.Dir(destPath), 0755); err != nil {
log.V(8).Error(err, "error creating directory for java file", "path", destPath)
continue
Expand Down Expand Up @@ -622,4 +626,4 @@ func toFilePathDependency(_ context.Context, filePath string) (javaArtifact, err
dep.Version = "0.0.0"
return dep, nil

}
}

0 comments on commit b6b0f12

Please sign in to comment.