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 package name escaping in UserService #3341

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 15 additions & 14 deletions github/users_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package github
import (
"context"
"fmt"
"net/url"
)

// ListPackages lists the packages for a user. Passing the empty string for "user" will
Expand Down Expand Up @@ -55,9 +56,9 @@ func (s *UsersService) ListPackages(ctx context.Context, user string, opts *Pack
func (s *UsersService) GetPackage(ctx context.Context, user, packageType, packageName string) (*Package, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/packages/%v/%v", user, packageType, packageName)
u = fmt.Sprintf("users/%v/packages/%v/%v", user, packageType, url.PathEscape(packageName))
} else {
u = fmt.Sprintf("user/packages/%v/%v", packageType, packageName)
u = fmt.Sprintf("user/packages/%v/%v", packageType, url.PathEscape(packageName))
}

req, err := s.client.NewRequest("GET", u, nil)
Expand Down Expand Up @@ -85,9 +86,9 @@ func (s *UsersService) GetPackage(ctx context.Context, user, packageType, packag
func (s *UsersService) DeletePackage(ctx context.Context, user, packageType, packageName string) (*Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/packages/%v/%v", user, packageType, packageName)
u = fmt.Sprintf("users/%v/packages/%v/%v", user, packageType, url.PathEscape(packageName))
} else {
u = fmt.Sprintf("user/packages/%v/%v", packageType, packageName)
u = fmt.Sprintf("user/packages/%v/%v", packageType, url.PathEscape(packageName))
}

req, err := s.client.NewRequest("DELETE", u, nil)
Expand All @@ -109,9 +110,9 @@ func (s *UsersService) DeletePackage(ctx context.Context, user, packageType, pac
func (s *UsersService) RestorePackage(ctx context.Context, user, packageType, packageName string) (*Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/packages/%v/%v/restore", user, packageType, packageName)
u = fmt.Sprintf("users/%v/packages/%v/%v/restore", user, packageType, url.PathEscape(packageName))
} else {
u = fmt.Sprintf("user/packages/%v/%v/restore", packageType, packageName)
u = fmt.Sprintf("user/packages/%v/%v/restore", packageType, url.PathEscape(packageName))
}

req, err := s.client.NewRequest("POST", u, nil)
Expand All @@ -133,9 +134,9 @@ func (s *UsersService) RestorePackage(ctx context.Context, user, packageType, pa
func (s *UsersService) PackageGetAllVersions(ctx context.Context, user, packageType, packageName string, opts *PackageListOptions) ([]*PackageVersion, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/packages/%v/%v/versions", user, packageType, packageName)
u = fmt.Sprintf("users/%v/packages/%v/%v/versions", user, packageType, url.PathEscape(packageName))
} else {
u = fmt.Sprintf("user/packages/%v/%v/versions", packageType, packageName)
u = fmt.Sprintf("user/packages/%v/%v/versions", packageType, url.PathEscape(packageName))
}
u, err := addOptions(u, opts)
if err != nil {
Expand Down Expand Up @@ -167,9 +168,9 @@ func (s *UsersService) PackageGetAllVersions(ctx context.Context, user, packageT
func (s *UsersService) PackageGetVersion(ctx context.Context, user, packageType, packageName string, packageVersionID int64) (*PackageVersion, *Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/packages/%v/%v/versions/%v", user, packageType, packageName, packageVersionID)
u = fmt.Sprintf("users/%v/packages/%v/%v/versions/%v", user, packageType, url.PathEscape(packageName), packageVersionID)
} else {
u = fmt.Sprintf("user/packages/%v/%v/versions/%v", packageType, packageName, packageVersionID)
u = fmt.Sprintf("user/packages/%v/%v/versions/%v", packageType, url.PathEscape(packageName), packageVersionID)
}

req, err := s.client.NewRequest("GET", u, nil)
Expand Down Expand Up @@ -197,9 +198,9 @@ func (s *UsersService) PackageGetVersion(ctx context.Context, user, packageType,
func (s *UsersService) PackageDeleteVersion(ctx context.Context, user, packageType, packageName string, packageVersionID int64) (*Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/packages/%v/%v/versions/%v", user, packageType, packageName, packageVersionID)
u = fmt.Sprintf("users/%v/packages/%v/%v/versions/%v", user, packageType, url.PathEscape(packageName), packageVersionID)
} else {
u = fmt.Sprintf("user/packages/%v/%v/versions/%v", packageType, packageName, packageVersionID)
u = fmt.Sprintf("user/packages/%v/%v/versions/%v", packageType, url.PathEscape(packageName), packageVersionID)
}

req, err := s.client.NewRequest("DELETE", u, nil)
Expand All @@ -221,9 +222,9 @@ func (s *UsersService) PackageDeleteVersion(ctx context.Context, user, packageTy
func (s *UsersService) PackageRestoreVersion(ctx context.Context, user, packageType, packageName string, packageVersionID int64) (*Response, error) {
var u string
if user != "" {
u = fmt.Sprintf("users/%v/packages/%v/%v/versions/%v/restore", user, packageType, packageName, packageVersionID)
u = fmt.Sprintf("users/%v/packages/%v/%v/versions/%v/restore", user, packageType, url.PathEscape(packageName), packageVersionID)
} else {
u = fmt.Sprintf("user/packages/%v/%v/versions/%v/restore", packageType, packageName, packageVersionID)
u = fmt.Sprintf("user/packages/%v/%v/versions/%v/restore", packageType, url.PathEscape(packageName), packageVersionID)
}

req, err := s.client.NewRequest("POST", u, nil)
Expand Down
Loading