From f66c5d85ab1c9dcf3c0de68b22fcfffa9a00010d Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Thu, 4 Jun 2026 21:48:50 +0200 Subject: [PATCH] Small fixes, better sanitization --- pkg/resource/files.go | 3 +-- pkg/validator/validator.go | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/resource/files.go b/pkg/resource/files.go index 795fc46..759a5cb 100644 --- a/pkg/resource/files.go +++ b/pkg/resource/files.go @@ -115,12 +115,11 @@ func findResourcesInReader(p string, f io.Reader, resources chan<- Resource, err func findResourcesInFile(p string, resources chan<- Resource, errors chan<- error, buf []byte) { f, err := os.Open(p) - defer f.Close() - if err != nil { errors <- DiscoveryError{p, err} return } + defer f.Close() findResourcesInReader(p, f, resources, errors, buf) } diff --git a/pkg/validator/validator.go b/pkg/validator/validator.go index 08bf16a..677db6b 100644 --- a/pkg/validator/validator.go +++ b/pkg/validator/validator.go @@ -103,7 +103,7 @@ func New(schemaLocations []string, opts Opts) (Validator, error) { return nil, fmt.Errorf("failed opening cache folder %s: %s", opts.Cache, err) } if !fi.IsDir() { - return nil, fmt.Errorf("cache folder %s is not a directory", err) + return nil, fmt.Errorf("cache folder %s is not a directory", opts.Cache) } filecache = cache.NewOnDiskCache(opts.Cache) @@ -292,13 +292,13 @@ func (val *v) Validate(filename string, r io.ReadCloser) []Result { // which is commonly used in Kubernetes operators for specifying intervals. // https://github.com/kubernetes/apiextensions-apiserver/blob/1ecd29f74da0639e2e6e3b8fac0c9bfd217e05eb/pkg/apis/apiextensions/v1/types_jsonschema.go#L71 func validateDuration(v any) error { - // Try validation with the Go duration format - if _, err := strfmt.ParseDuration(v.(string)); err == nil { + s, ok := v.(string) + if !ok { return nil } - s, ok := v.(string) - if !ok { + // Try validation with the Go duration format + if _, err := strfmt.ParseDuration(s); err == nil { return nil }