Skip to content

Commit 663874e

Browse files
zeripathlafriks
authored andcommitted
Use url.PathEscape to escape the branchname (#6304)
* Use url.PathEscape to escape the branchname * GetRepositoryByOwnerAndName should also have url.PathEscape as the owner and reponame are provided by the client
1 parent 50631b5 commit 663874e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

modules/private/branch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package private
77
import (
88
"encoding/json"
99
"fmt"
10+
"net/url"
1011

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

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

modules/private/internal.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"net"
1212
"net/http"
13+
"net/url"
1314

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

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

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

0 commit comments

Comments
 (0)