Procházet zdrojové kódy

repo: remove legacy sanitizer for repository description

Related to #4329.
Unknwon před 8 roky
rodič
revize
3144be5c81
3 změnil soubory, kde provedl 2 přidání a 16 odebrání
  1. 0 14
      models/repo.go
  2. 1 1
      templates/explore/repo_list.tmpl
  3. 1 1
      templates/repo/home.tmpl

+ 0 - 14
models/repo.go

@@ -7,13 +7,11 @@ package models
 import (
 	"bytes"
 	"fmt"
-	"html/template"
 	"io/ioutil"
 	"os"
 	"os/exec"
 	"path"
 	"path/filepath"
-	"regexp"
 	"sort"
 	"strings"
 	"time"
@@ -493,18 +491,6 @@ func (repo *Repository) NextIssueIndex() int64 {
 	return int64(repo.NumIssues+repo.NumPulls) + 1
 }
 
-var (
-	DescPattern = regexp.MustCompile(`https?://\S+`)
-)
-
-// DescriptionHtml does special handles to description and return HTML string.
-func (repo *Repository) DescriptionHtml() template.HTML {
-	sanitize := func(s string) string {
-		return fmt.Sprintf(`<a href="%[1]s" target="_blank">%[1]s</a>`, s)
-	}
-	return template.HTML(DescPattern.ReplaceAllStringFunc(markdown.Sanitizer.Sanitize(repo.Description), sanitize))
-}
-
 func (repo *Repository) LocalCopyPath() string {
 	return path.Join(setting.AppDataPath, "tmp/local-repo", com.ToStr(repo.ID))
 }

+ 1 - 1
templates/explore/repo_list.tmpl

@@ -16,7 +16,7 @@
 					<span class="text grey"><i class="octicon octicon-git-branch"></i> {{.NumForks}}</span>
 				</div>
 			</div>
-			{{if .DescriptionHtml}}<p class="has-emoji">{{.DescriptionHtml}}</p>{{end}}
+			{{if .Description}}<p class="has-emoji">{{.Description | Str2html}}</p>{{end}}
 			<p class="time">{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}</p>
 		</div>
 	{{end}}

+ 1 - 1
templates/repo/home.tmpl

@@ -5,7 +5,7 @@
 		{{template "base/alert" .}}
 		{{if .PageIsRepoHome}}
 			<p id="repo-desc">
-				{{if .Repository.DescriptionHtml}}<span class="description has-emoji">{{.Repository.DescriptionHtml}}</span>{{else}}<span class="no-description text-italic">{{.i18n.Tr "repo.no_desc"}}</span>{{end}}
+				{{if .Repository.Description}}<span class="description has-emoji">{{.Repository.Description | Str2html}}</span>{{else}}<span class="no-description text-italic">{{.i18n.Tr "repo.no_desc"}}</span>{{end}}
 				<a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>
 			</p>
 			<div class="ui segment" id="git-stats">