From 3d306c709e6e451b5b9a909a99fdad7c92946198 Mon Sep 17 00:00:00 2001 From: zongz Date: Thu, 20 Jul 2023 14:31:03 +0800 Subject: [PATCH] fix: fix the null pointer when 'kpm pull'. --- pkg/cmd/cmd_pull.go | 2 +- pkg/utils/utils.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/cmd_pull.go b/pkg/cmd/cmd_pull.go index 8717d3b1..0106ff7b 100644 --- a/pkg/cmd/cmd_pull.go +++ b/pkg/cmd/cmd_pull.go @@ -66,7 +66,7 @@ func KpmPull(c *cli.Context) error { ociOpt, event := opt.ParseOciOptionFromOciUrl(ociUrlOrPkgName, tag) - if event.Type() == reporter.IsNotUrl || event.Type() == reporter.UrlSchemeNotOci { + if event != nil && (event.Type() == reporter.IsNotUrl || event.Type() == reporter.UrlSchemeNotOci) { settings := settings.GetSettings() if settings.ErrorEvent != nil { return settings.ErrorEvent diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index f0d84d52..cbb3480d 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -364,5 +364,7 @@ func RmNewline(s string) string { // JoinPath will join the 'elem' to the 'base' with '/'. func JoinPath(base, elem string) string { - return fmt.Sprintf("%s/%s", base, elem) + base = strings.TrimSuffix(base, "/") + elem = strings.TrimPrefix(elem, "/") + return base + "/" + elem }