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