File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -204,6 +204,14 @@ type Repository struct {
204204 UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
205205}
206206
207+ // SanitizedOriginalURL returns a sanitized OriginalURL
208+ func (repo * Repository ) SanitizedOriginalURL () string {
209+ if repo .OriginalURL == "" {
210+ return ""
211+ }
212+ return util .SanitizeURLCredentials (repo .OriginalURL , false )
213+ }
214+
207215// ColorFormat returns a colored string to represent this repo
208216func (repo * Repository ) ColorFormat (s fmt.State ) {
209217 var ownerName interface {}
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ package util
77import (
88 "net/url"
99 "strings"
10+
11+ "code.gitea.io/gitea/modules/log"
1012)
1113
1214// urlSafeError wraps an error whose message may contain a sensitive URL
@@ -36,6 +38,7 @@ func SanitizeMessage(message, unsanitizedURL string) string {
3638func SanitizeURLCredentials (unsanitizedURL string , usePlaceholder bool ) string {
3739 u , err := url .Parse (unsanitizedURL )
3840 if err != nil {
41+ log .Error ("parse url %s failed: %v" , unsanitizedURL , err )
3942 // don't log the error, since it might contain unsanitized URL.
4043 return "(unparsable url)"
4144 }
Original file line number Diff line number Diff line change 1+ // Copyright 2020 The Gitea Authors. All rights reserved.
2+ // Use of this source code is governed by a MIT-style
3+ // license that can be found in the LICENSE file.
4+
5+ package util
6+
7+ import (
8+ "testing"
9+
10+ "github.com/stretchr/testify/assert"
11+ )
12+
13+ func TestSanitizeURLCredentials (t * testing.T ) {
14+ var kases = map [string ]string {
15+ "https://github.com/go-gitea/test_repo.git" : "https://github.com/go-gitea/test_repo.git" ,
16+ "https://mytoken@github.com/go-gitea/test_repo.git" : "https://github.com/go-gitea/test_repo.git" ,
17+ "http://github.com/go-gitea/test_repo.git" : "http://github.com/go-gitea/test_repo.git" ,
18+ "/test/repos/repo1" : "/test/repos/repo1" ,
19+ "git@github.com:go-gitea/test_repo.git" : "(unparsable url)" ,
20+ }
21+
22+ for source , value := range kases {
23+ assert .EqualValues (t , value , SanitizeURLCredentials (source , false ))
24+ }
25+ }
Original file line number Diff line number Diff line change 1414 {{if and .RelAvatarLink .IsPrivate }}<i class= " mega-octicon octicon-lock" ></i>{{end }}
1515 {{if .IsTemplate }}<i class= " icon fa-copy" ></i>{{end }}
1616 {{if .IsArchived }}<i class= " archive icon archived-icon" ></i>{{end }}
17- {{if .IsMirror }}<div class= " fork-flag" >{{$ .i18n.Tr " repo.mirror_from" }} <a target= " _blank" rel= " noopener noreferrer" href= " {{MirrorAddress $.Mirror}}" >{{MirrorAddress $ .Mirror }}</a></div>{{end }}
17+ {{if .IsMirror }}<div class= " fork-flag" >{{$ .i18n.Tr " repo.mirror_from" }} <a target= " _blank" rel= " noopener noreferrer" href= " {{if .SanitizedOriginalURL}}{{.SanitizedOriginalURL}}{{else}}{{ MirrorAddress $.Mirror}}{{end}} " >{{if .SanitizedOriginalURL }}{{ .SanitizedOriginalURL }}{{ else }}{{ MirrorAddress $ .Mirror }}{{ end }}</a></div>{{end }}
1818 {{if .IsFork }}<div class= " fork-flag" >{{$ .i18n.Tr " repo.forked_from" }} <a href= " {{.BaseRepo.Link}}" >{{SubStr .BaseRepo.RelLink 1 -1}}</a></div>{{end }}
1919 {{if .IsGenerated }}<div class= " fork-flag" >{{$ .i18n.Tr " repo.generated_from" }} <a href= " {{.TemplateRepo.Link}}" >{{SubStr .TemplateRepo.RelLink 1 -1}}</a></div>{{end }}
2020 </div>
You can’t perform that action at this time.
0 commit comments