Skip to content

Commit

Permalink
Use url.PathEscape to escape the branchname (#6304)
Browse files Browse the repository at this point in the history
* Use url.PathEscape to escape the branchname

* GetRepositoryByOwnerAndName should also have url.PathEscape as the owner and reponame are provided by the client
  • Loading branch information
zeripath authored and lafriks committed Mar 11, 2019
1 parent 50631b5 commit 663874e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion modules/private/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package private
import (
"encoding/json"
"fmt"
"net/url"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
Expand All @@ -16,7 +17,7 @@ import (
// GetProtectedBranchBy get protected branch information
func GetProtectedBranchBy(repoID int64, branchName string) (*models.ProtectedBranch, error) {
// Ask for running deliver hook and test pull request tasks.
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/branch/%d/%s", repoID, branchName)
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/branch/%d/%s", repoID, url.PathEscape(branchName))
log.GitLogger.Trace("GetProtectedBranchBy: %s", reqURL)

resp, err := newInternalRequest(reqURL, "GET").Response()
Expand Down
3 changes: 2 additions & 1 deletion modules/private/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"net"
"net/http"
"net/url"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/httplib"
Expand Down Expand Up @@ -76,7 +77,7 @@ func CheckUnitUser(userID, repoID int64, isAdmin bool, unitType models.UnitType)

// GetRepositoryByOwnerAndName returns the repository by given ownername and reponame.
func GetRepositoryByOwnerAndName(ownerName, repoName string) (*models.Repository, error) {
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/repo/%s/%s", ownerName, repoName)
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/repo/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
log.GitLogger.Trace("GetRepositoryByOwnerAndName: %s", reqURL)

resp, err := newInternalRequest(reqURL, "GET").Response()
Expand Down

0 comments on commit 663874e

Please sign in to comment.