From a1d3dcf34557b8dd552d29f0c666627b46a29af7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 15 Jan 2026 19:51:57 +0000 Subject: [PATCH] Improve pathRel to handle edge cases correctly - Handle case where basepath equals targpath by returning "." - Ensure basepath is treated as directory with trailing slash to avoid false prefix matches - Fix linter issue by using += operator Addresses code review feedback. Co-authored-by: rchincha <45800463+rchincha@users.noreply.github.com> --- pkg/storage/imagestore/imagestore.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/storage/imagestore/imagestore.go b/pkg/storage/imagestore/imagestore.go index bcf2f903..c94f0129 100644 --- a/pkg/storage/imagestore/imagestore.go +++ b/pkg/storage/imagestore/imagestore.go @@ -80,14 +80,23 @@ func (is *ImageStore) pathRel(basepath, targpath string) (string, error) { basepath = path.Clean(basepath) targpath = path.Clean(targpath) + // Handle case where paths are equal + if basepath == targpath { + return ".", nil + } + + // Ensure basepath is treated as a directory by adding trailing slash + if !strings.HasSuffix(basepath, "/") { + basepath += "/" + } + // Check if targpath starts with basepath if !strings.HasPrefix(targpath, basepath) { return "", fmt.Errorf("%w: path %s is not under base path %s", zerr.ErrBadConfig, targpath, basepath) } - // Remove basepath prefix and leading slash + // Remove basepath prefix (which now includes trailing slash) rel := strings.TrimPrefix(targpath, basepath) - rel = strings.TrimPrefix(rel, "/") return rel, nil }