Skip to content

Commit

Permalink
fix: validate snippet filenames before reading & increase error verbo…
Browse files Browse the repository at this point in the history
…sity

fixes #443
  • Loading branch information
jankal authored and shyim committed Nov 27, 2024
1 parent 9e5a40d commit 2e0925b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/project/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2e0925b

Please sign in to comment.