Skip to content

Commit 1e744e5

Browse files
author
Sander van Harmelen
authored
Merge pull request xanzy#613 from xanzy/svh/f-escape
Add a custom escape function.
2 parents d544682 + 2e9a2b3 commit 1e744e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+393
-460
lines changed

access_requests.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gitlab
22

33
import (
44
"fmt"
5-
"net/url"
65
"time"
76
)
87

@@ -45,7 +44,7 @@ func (s *AccessRequestsService) ListProjectAccessRequests(pid interface{}, opt *
4544
if err != nil {
4645
return nil, nil, err
4746
}
48-
u := fmt.Sprintf("projects/%s/access_requests", url.QueryEscape(project))
47+
u := fmt.Sprintf("projects/%s/access_requests", pathEscape(project))
4948

5049
req, err := s.client.NewRequest("GET", u, opt, options)
5150
if err != nil {
@@ -71,7 +70,7 @@ func (s *AccessRequestsService) ListGroupAccessRequests(gid interface{}, opt *Li
7170
if err != nil {
7271
return nil, nil, err
7372
}
74-
u := fmt.Sprintf("groups/%s/access_requests", url.QueryEscape(group))
73+
u := fmt.Sprintf("groups/%s/access_requests", pathEscape(group))
7574

7675
req, err := s.client.NewRequest("GET", u, opt, options)
7776
if err != nil {
@@ -97,7 +96,7 @@ func (s *AccessRequestsService) RequestProjectAccess(pid interface{}, options ..
9796
if err != nil {
9897
return nil, nil, err
9998
}
100-
u := fmt.Sprintf("projects/%s/access_requests", url.QueryEscape(project))
99+
u := fmt.Sprintf("projects/%s/access_requests", pathEscape(project))
101100

102101
req, err := s.client.NewRequest("POST", u, nil, options)
103102
if err != nil {
@@ -123,7 +122,7 @@ func (s *AccessRequestsService) RequestGroupAccess(gid interface{}, options ...O
123122
if err != nil {
124123
return nil, nil, err
125124
}
126-
u := fmt.Sprintf("groups/%s/access_requests", url.QueryEscape(group))
125+
u := fmt.Sprintf("groups/%s/access_requests", pathEscape(group))
127126

128127
req, err := s.client.NewRequest("POST", u, nil, options)
129128
if err != nil {
@@ -157,7 +156,7 @@ func (s *AccessRequestsService) ApproveProjectAccessRequest(pid interface{}, use
157156
if err != nil {
158157
return nil, nil, err
159158
}
160-
u := fmt.Sprintf("projects/%s/access_requests/%d/approve", url.QueryEscape(project), user)
159+
u := fmt.Sprintf("projects/%s/access_requests/%d/approve", pathEscape(project), user)
161160

162161
req, err := s.client.NewRequest("PUT", u, opt, options)
163162
if err != nil {
@@ -182,7 +181,7 @@ func (s *AccessRequestsService) ApproveGroupAccessRequest(gid interface{}, user
182181
if err != nil {
183182
return nil, nil, err
184183
}
185-
u := fmt.Sprintf("groups/%s/access_requests/%d/approve", url.QueryEscape(group), user)
184+
u := fmt.Sprintf("groups/%s/access_requests/%d/approve", pathEscape(group), user)
186185

187186
req, err := s.client.NewRequest("PUT", u, opt, options)
188187
if err != nil {
@@ -207,7 +206,7 @@ func (s *AccessRequestsService) DenyProjectAccessRequest(pid interface{}, user i
207206
if err != nil {
208207
return nil, err
209208
}
210-
u := fmt.Sprintf("projects/%s/access_requests/%d", url.QueryEscape(project), user)
209+
u := fmt.Sprintf("projects/%s/access_requests/%d", pathEscape(project), user)
211210

212211
req, err := s.client.NewRequest("DELETE", u, nil, options)
213212
if err != nil {
@@ -226,7 +225,7 @@ func (s *AccessRequestsService) DenyGroupAccessRequest(gid interface{}, user int
226225
if err != nil {
227226
return nil, err
228227
}
229-
u := fmt.Sprintf("groups/%s/access_requests/%d", url.QueryEscape(group), user)
228+
u := fmt.Sprintf("groups/%s/access_requests/%d", pathEscape(group), user)
230229

231230
req, err := s.client.NewRequest("DELETE", u, nil, options)
232231
if err != nil {

award_emojis.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package gitlab
1818

1919
import (
2020
"fmt"
21-
"net/url"
2221
"time"
2322
)
2423

@@ -93,7 +92,7 @@ func (s *AwardEmojiService) listAwardEmoji(pid interface{}, resource string, res
9392
return nil, nil, err
9493
}
9594
u := fmt.Sprintf("projects/%s/%s/%d/award_emoji",
96-
url.QueryEscape(project),
95+
pathEscape(project),
9796
resource,
9897
resourceID,
9998
)
@@ -142,7 +141,7 @@ func (s *AwardEmojiService) getAwardEmoji(pid interface{}, resource string, reso
142141
return nil, nil, err
143142
}
144143
u := fmt.Sprintf("projects/%s/%s/%d/award_emoji/%d",
145-
url.QueryEscape(project),
144+
pathEscape(project),
146145
resource,
147146
resourceID,
148147
awardID,
@@ -201,7 +200,7 @@ func (s *AwardEmojiService) createAwardEmoji(pid interface{}, resource string, r
201200
return nil, nil, err
202201
}
203202
u := fmt.Sprintf("projects/%s/%s/%d/award_emoji",
204-
url.QueryEscape(project),
203+
pathEscape(project),
205204
resource,
206205
resourceID,
207206
)
@@ -253,7 +252,7 @@ func (s *AwardEmojiService) deleteAwardEmoji(pid interface{}, resource string, r
253252
if err != nil {
254253
return nil, err
255254
}
256-
u := fmt.Sprintf("projects/%s/%s/%d/award_emoji/%d", url.QueryEscape(project), resource,
255+
u := fmt.Sprintf("projects/%s/%s/%d/award_emoji/%d", pathEscape(project), resource,
257256
resourceID, awardID)
258257

259258
req, err := s.client.NewRequest("DELETE", u, nil, options)
@@ -295,7 +294,7 @@ func (s *AwardEmojiService) listAwardEmojiOnNote(pid interface{}, resources stri
295294
if err != nil {
296295
return nil, nil, err
297296
}
298-
u := fmt.Sprintf("projects/%s/%s/%d/notes/%d/award_emoji", url.QueryEscape(project), resources,
297+
u := fmt.Sprintf("projects/%s/%s/%d/notes/%d/award_emoji", pathEscape(project), resources,
299298
ressourceID, noteID)
300299

301300
req, err := s.client.NewRequest("GET", u, opt, options)
@@ -344,7 +343,7 @@ func (s *AwardEmojiService) getSingleNoteAwardEmoji(pid interface{}, ressource s
344343
return nil, nil, err
345344
}
346345
u := fmt.Sprintf("projects/%s/%s/%d/notes/%d/award_emoji/%d",
347-
url.QueryEscape(project),
346+
pathEscape(project),
348347
ressource,
349348
resourceID,
350349
noteID,
@@ -400,7 +399,7 @@ func (s *AwardEmojiService) createAwardEmojiOnNote(pid interface{}, resource str
400399
return nil, nil, err
401400
}
402401
u := fmt.Sprintf("projects/%s/%s/%d/notes/%d/award_emoji",
403-
url.QueryEscape(project),
402+
pathEscape(project),
404403
resource,
405404
resourceID,
406405
noteID,
@@ -452,7 +451,7 @@ func (s *AwardEmojiService) deleteAwardEmojiOnNote(pid interface{}, resource str
452451
return nil, err
453452
}
454453
u := fmt.Sprintf("projects/%s/%s/%d/notes/%d/award_emoji/%d",
455-
url.QueryEscape(project),
454+
pathEscape(project),
456455
resource,
457456
resourceID,
458457
noteID,

boards.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package gitlab
1818

1919
import (
2020
"fmt"
21-
"net/url"
2221
)
2322

2423
// IssueBoardsService handles communication with the issue board related
@@ -72,7 +71,7 @@ func (s *IssueBoardsService) CreateIssueBoard(pid interface{}, opt *CreateIssueB
7271
if err != nil {
7372
return nil, nil, err
7473
}
75-
u := fmt.Sprintf("projects/%s/boards", url.QueryEscape(project))
74+
u := fmt.Sprintf("projects/%s/boards", pathEscape(project))
7675

7776
req, err := s.client.NewRequest("POST", u, opt, options)
7877
if err != nil {
@@ -107,7 +106,7 @@ func (s *IssueBoardsService) UpdateIssueBoard(pid interface{}, board int, opt *U
107106
if err != nil {
108107
return nil, nil, err
109108
}
110-
u := fmt.Sprintf("projects/%s/boards/%d", url.QueryEscape(project), board)
109+
u := fmt.Sprintf("projects/%s/boards/%d", pathEscape(project), board)
111110

112111
req, err := s.client.NewRequest("PUT", u, opt, options)
113112
if err != nil {
@@ -131,7 +130,7 @@ func (s *IssueBoardsService) DeleteIssueBoard(pid interface{}, board int, option
131130
if err != nil {
132131
return nil, err
133132
}
134-
u := fmt.Sprintf("projects/%s/boards/%d", url.QueryEscape(project), board)
133+
u := fmt.Sprintf("projects/%s/boards/%d", pathEscape(project), board)
135134

136135
req, err := s.client.NewRequest("DELETE", u, nil, options)
137136
if err != nil {
@@ -154,7 +153,7 @@ func (s *IssueBoardsService) ListIssueBoards(pid interface{}, opt *ListIssueBoar
154153
if err != nil {
155154
return nil, nil, err
156155
}
157-
u := fmt.Sprintf("projects/%s/boards", url.QueryEscape(project))
156+
u := fmt.Sprintf("projects/%s/boards", pathEscape(project))
158157

159158
req, err := s.client.NewRequest("GET", u, opt, options)
160159
if err != nil {
@@ -178,7 +177,7 @@ func (s *IssueBoardsService) GetIssueBoard(pid interface{}, board int, options .
178177
if err != nil {
179178
return nil, nil, err
180179
}
181-
u := fmt.Sprintf("projects/%s/boards/%d", url.QueryEscape(project), board)
180+
u := fmt.Sprintf("projects/%s/boards/%d", pathEscape(project), board)
182181

183182
req, err := s.client.NewRequest("GET", u, nil, options)
184183
if err != nil {
@@ -208,7 +207,7 @@ func (s *IssueBoardsService) GetIssueBoardLists(pid interface{}, board int, opt
208207
if err != nil {
209208
return nil, nil, err
210209
}
211-
u := fmt.Sprintf("projects/%s/boards/%d/lists", url.QueryEscape(project), board)
210+
u := fmt.Sprintf("projects/%s/boards/%d/lists", pathEscape(project), board)
212211

213212
req, err := s.client.NewRequest("GET", u, opt, options)
214213
if err != nil {
@@ -233,7 +232,7 @@ func (s *IssueBoardsService) GetIssueBoardList(pid interface{}, board, list int,
233232
return nil, nil, err
234233
}
235234
u := fmt.Sprintf("projects/%s/boards/%d/lists/%d",
236-
url.QueryEscape(project),
235+
pathEscape(project),
237236
board,
238237
list,
239238
)
@@ -268,7 +267,7 @@ func (s *IssueBoardsService) CreateIssueBoardList(pid interface{}, board int, op
268267
if err != nil {
269268
return nil, nil, err
270269
}
271-
u := fmt.Sprintf("projects/%s/boards/%d/lists", url.QueryEscape(project), board)
270+
u := fmt.Sprintf("projects/%s/boards/%d/lists", pathEscape(project), board)
272271

273272
req, err := s.client.NewRequest("POST", u, opt, options)
274273
if err != nil {
@@ -301,7 +300,7 @@ func (s *IssueBoardsService) UpdateIssueBoardList(pid interface{}, board, list i
301300
return nil, nil, err
302301
}
303302
u := fmt.Sprintf("projects/%s/boards/%d/lists/%d",
304-
url.QueryEscape(project),
303+
pathEscape(project),
305304
board,
306305
list,
307306
)
@@ -331,7 +330,7 @@ func (s *IssueBoardsService) DeleteIssueBoardList(pid interface{}, board, list i
331330
return nil, err
332331
}
333332
u := fmt.Sprintf("projects/%s/boards/%d/lists/%d",
334-
url.QueryEscape(project),
333+
pathEscape(project),
335334
board,
336335
list,
337336
)

branches.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (s *BranchesService) ListBranches(pid interface{}, opts *ListBranchesOption
6161
if err != nil {
6262
return nil, nil, err
6363
}
64-
u := fmt.Sprintf("projects/%s/repository/branches", url.QueryEscape(project))
64+
u := fmt.Sprintf("projects/%s/repository/branches", pathEscape(project))
6565

6666
req, err := s.client.NewRequest("GET", u, opts, options)
6767
if err != nil {
@@ -86,7 +86,7 @@ func (s *BranchesService) GetBranch(pid interface{}, branch string, options ...O
8686
if err != nil {
8787
return nil, nil, err
8888
}
89-
u := fmt.Sprintf("projects/%s/repository/branches/%s", url.QueryEscape(project), url.QueryEscape(branch))
89+
u := fmt.Sprintf("projects/%s/repository/branches/%s", pathEscape(project), url.PathEscape(branch))
9090

9191
req, err := s.client.NewRequest("GET", u, nil, options)
9292
if err != nil {
@@ -122,7 +122,7 @@ func (s *BranchesService) ProtectBranch(pid interface{}, branch string, opts *Pr
122122
if err != nil {
123123
return nil, nil, err
124124
}
125-
u := fmt.Sprintf("projects/%s/repository/branches/%s/protect", url.QueryEscape(project), url.QueryEscape(branch))
125+
u := fmt.Sprintf("projects/%s/repository/branches/%s/protect", pathEscape(project), url.PathEscape(branch))
126126

127127
req, err := s.client.NewRequest("PUT", u, opts, options)
128128
if err != nil {
@@ -149,7 +149,7 @@ func (s *BranchesService) UnprotectBranch(pid interface{}, branch string, option
149149
if err != nil {
150150
return nil, nil, err
151151
}
152-
u := fmt.Sprintf("projects/%s/repository/branches/%s/unprotect", url.QueryEscape(project), url.QueryEscape(branch))
152+
u := fmt.Sprintf("projects/%s/repository/branches/%s/unprotect", pathEscape(project), url.PathEscape(branch))
153153

154154
req, err := s.client.NewRequest("PUT", u, nil, options)
155155
if err != nil {
@@ -183,7 +183,7 @@ func (s *BranchesService) CreateBranch(pid interface{}, opt *CreateBranchOptions
183183
if err != nil {
184184
return nil, nil, err
185185
}
186-
u := fmt.Sprintf("projects/%s/repository/branches", url.QueryEscape(project))
186+
u := fmt.Sprintf("projects/%s/repository/branches", pathEscape(project))
187187

188188
req, err := s.client.NewRequest("POST", u, opt, options)
189189
if err != nil {
@@ -208,7 +208,7 @@ func (s *BranchesService) DeleteBranch(pid interface{}, branch string, options .
208208
if err != nil {
209209
return nil, err
210210
}
211-
u := fmt.Sprintf("projects/%s/repository/branches/%s", url.QueryEscape(project), url.QueryEscape(branch))
211+
u := fmt.Sprintf("projects/%s/repository/branches/%s", pathEscape(project), url.PathEscape(branch))
212212

213213
req, err := s.client.NewRequest("DELETE", u, nil, options)
214214
if err != nil {
@@ -227,7 +227,7 @@ func (s *BranchesService) DeleteMergedBranches(pid interface{}, options ...Optio
227227
if err != nil {
228228
return nil, err
229229
}
230-
u := fmt.Sprintf("projects/%s/repository/merged_branches", url.QueryEscape(project))
230+
u := fmt.Sprintf("projects/%s/repository/merged_branches", pathEscape(project))
231231

232232
req, err := s.client.NewRequest("DELETE", u, nil, options)
233233
if err != nil {

build_variables.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gitlab
22

33
import (
44
"fmt"
5-
"net/url"
65
)
76

87
// BuildVariablesService handles communication with the project variables related methods
@@ -41,7 +40,7 @@ func (s *BuildVariablesService) ListBuildVariables(pid interface{}, opts *ListBu
4140
if err != nil {
4241
return nil, nil, err
4342
}
44-
u := fmt.Sprintf("projects/%s/variables", url.QueryEscape(project))
43+
u := fmt.Sprintf("projects/%s/variables", pathEscape(project))
4544

4645
req, err := s.client.NewRequest("GET", u, opts, options)
4746
if err != nil {
@@ -66,7 +65,7 @@ func (s *BuildVariablesService) GetBuildVariable(pid interface{}, key string, op
6665
if err != nil {
6766
return nil, nil, err
6867
}
69-
u := fmt.Sprintf("projects/%s/variables/%s", url.QueryEscape(project), key)
68+
u := fmt.Sprintf("projects/%s/variables/%s", pathEscape(project), key)
7069

7170
req, err := s.client.NewRequest("GET", u, nil, options)
7271
if err != nil {
@@ -101,7 +100,7 @@ func (s *BuildVariablesService) CreateBuildVariable(pid interface{}, opt *Create
101100
if err != nil {
102101
return nil, nil, err
103102
}
104-
u := fmt.Sprintf("projects/%s/variables", url.QueryEscape(project))
103+
u := fmt.Sprintf("projects/%s/variables", pathEscape(project))
105104

106105
req, err := s.client.NewRequest("POST", u, opt, options)
107106
if err != nil {
@@ -137,7 +136,7 @@ func (s *BuildVariablesService) UpdateBuildVariable(pid interface{}, key string,
137136
if err != nil {
138137
return nil, nil, err
139138
}
140-
u := fmt.Sprintf("projects/%s/variables/%s", url.QueryEscape(project), key)
139+
u := fmt.Sprintf("projects/%s/variables/%s", pathEscape(project), key)
141140

142141
req, err := s.client.NewRequest("PUT", u, opt, options)
143142
if err != nil {
@@ -162,7 +161,7 @@ func (s *BuildVariablesService) RemoveBuildVariable(pid interface{}, key string,
162161
if err != nil {
163162
return nil, err
164163
}
165-
u := fmt.Sprintf("projects/%s/variables/%s", url.QueryEscape(project), key)
164+
u := fmt.Sprintf("projects/%s/variables/%s", pathEscape(project), key)
166165

167166
req, err := s.client.NewRequest("DELETE", u, nil, options)
168167
if err != nil {

ci_yml_templates.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gitlab
22

33
import (
44
"fmt"
5-
"net/url"
65
)
76

87
// CIYMLTemplatesService handles communication with the gitlab
@@ -53,7 +52,7 @@ func (s *CIYMLTemplatesService) ListAllTemplates(opt *ListCIYMLTemplatesOptions,
5352
// GitLab API docs:
5453
// https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html#single-gitlab-ci-yml-template
5554
func (s *CIYMLTemplatesService) GetTemplate(key string, options ...OptionFunc) (*CIYMLTemplate, *Response, error) {
56-
u := fmt.Sprintf("templates/gitlab_ci_ymls/%s", url.QueryEscape(key))
55+
u := fmt.Sprintf("templates/gitlab_ci_ymls/%s", pathEscape(key))
5756

5857
req, err := s.client.NewRequest("GET", u, nil, options)
5958
if err != nil {

0 commit comments

Comments
 (0)