From 2e0925b522c2813187ed7c4bb7199f69bdddabc6 Mon Sep 17 00:00:00 2001 From: Alex Jank Date: Wed, 27 Nov 2024 11:37:48 +0100 Subject: [PATCH] fix: validate snippet filenames before reading & increase error verbosity fixes #443 --- cmd/project/ci.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/project/ci.go b/cmd/project/ci.go index 2043541..ed55464 100644 --- a/cmd/project/ci.go +++ b/cmd/project/ci.go @@ -348,6 +348,13 @@ func cleanupAdministrationFiles(ctx context.Context, folder string) error { languageName := strings.TrimSuffix(filepath.Base(path), fileExt) + if _, err := language.Parse(languageName); err != nil { + logging.FromContext(ctx).Infof("Ignoring invalid locale filename %s", path) + // we can safely ignore the error from language.Parse as we use language.Parse to check and stop processing this file + // thus checking for the error is the point of this condition + return nil //nolint:nilerr + } + if language.Make(languageName).IsRoot() { return nil } @@ -389,7 +396,7 @@ func cleanupAdministrationFiles(ctx context.Context, folder string) error { } if err := json.Unmarshal(data, &snippetFile); err != nil { - return err + return fmt.Errorf("unable to parse %s: %w", file, err) } if err := mergo.Merge(&merged, snippetFile, mergo.WithOverride); err != nil {