Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate snippet filenames before reading & increase error verbosity #444

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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