Skip to content

Commit

Permalink
Make GetRepositoryByName more safer (go-gitea#31712)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored and GiteaBot committed Jul 29, 2024
1 parent 0fb1c1f commit b130081
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions models/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,17 +741,18 @@ func GetRepositoryByOwnerAndName(ctx context.Context, ownerName, repoName string

// GetRepositoryByName returns the repository by given name under user if exists.
func GetRepositoryByName(ctx context.Context, ownerID int64, name string) (*Repository, error) {
repo := &Repository{
OwnerID: ownerID,
LowerName: strings.ToLower(name),
}
has, err := db.GetEngine(ctx).Get(repo)
var repo Repository
has, err := db.GetEngine(ctx).
Where("`owner_id`=?", ownerID).
And("`lower_name`=?", strings.ToLower(name)).
NoAutoCondition().
Get(&repo)
if err != nil {
return nil, err
} else if !has {
return nil, ErrRepoNotExist{0, ownerID, "", name}
}
return repo, err
return &repo, err
}

// getRepositoryURLPathSegments returns segments (owner, reponame) extracted from a url
Expand Down

0 comments on commit b130081

Please sign in to comment.