@@ -16,6 +16,7 @@ import (
16
16
"code.gitea.io/gitea/modules/git"
17
17
"code.gitea.io/gitea/modules/setting"
18
18
api "code.gitea.io/gitea/modules/structs"
19
+ "code.gitea.io/gitea/modules/util"
19
20
)
20
21
21
22
// ContentType repo content type
@@ -159,7 +160,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
159
160
return nil , fmt .Errorf ("no commit found for the ref [ref: %s]" , ref )
160
161
}
161
162
162
- selfURL , err := url .Parse (fmt . Sprintf ( "%s /contents/%s?ref=%s" , repo . APIURL (), treePath , origRef ))
163
+ selfURL , err := url .Parse (repo . APIURL () + " /contents/" + util . PathEscapeSegments ( treePath ) + "?ref=" + url . QueryEscape ( origRef ))
163
164
if err != nil {
164
165
return nil , err
165
166
}
@@ -218,23 +219,23 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
218
219
}
219
220
// Handle links
220
221
if entry .IsRegular () || entry .IsLink () {
221
- downloadURL , err := url .Parse (fmt . Sprintf ( "%s /raw/%s/%s/%s" , repo . HTMLURL (), refType , ref , treePath ))
222
+ downloadURL , err := url .Parse (repo . HTMLURL () + " /raw/" + url . PathEscape ( string ( refType )) + "/" + util . PathEscapeSegments ( ref ) + "/" + util . PathEscapeSegments ( treePath ))
222
223
if err != nil {
223
224
return nil , err
224
225
}
225
226
downloadURLString := downloadURL .String ()
226
227
contentsResponse .DownloadURL = & downloadURLString
227
228
}
228
229
if ! entry .IsSubModule () {
229
- htmlURL , err := url .Parse (fmt . Sprintf ( "%s /src/%s/%s/%s" , repo . HTMLURL (), refType , ref , treePath ))
230
+ htmlURL , err := url .Parse (repo . HTMLURL () + " /src/" + url . PathEscape ( string ( refType )) + "/" + util . PathEscapeSegments ( ref ) + "/" + util . PathEscapeSegments ( treePath ))
230
231
if err != nil {
231
232
return nil , err
232
233
}
233
234
htmlURLString := htmlURL .String ()
234
235
contentsResponse .HTMLURL = & htmlURLString
235
236
contentsResponse .Links .HTMLURL = & htmlURLString
236
237
237
- gitURL , err := url .Parse (fmt . Sprintf ( "%s /git/blobs/%s" , repo . APIURL (), entry .ID .String ()))
238
+ gitURL , err := url .Parse (repo . APIURL () + " /git/blobs/" + url . PathEscape ( entry .ID .String ()))
238
239
if err != nil {
239
240
return nil , err
240
241
}
0 commit comments