瀏覽代碼

Escape tags and quotes in links.

tags/v0.9.99
Justin Nuß 9 年之前
父節點
當前提交
636a78fed1
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8
    1
      models/repo.go

+ 8
- 1
models/repo.go 查看文件

@@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"html"
"html/template"
"os"
"path"
@@ -152,7 +153,13 @@ func (repo *Repository) GetOwner() (err error) {
}

func (repo *Repository) DescriptionHtml() template.HTML {
return template.HTML(DescriptionPattern.ReplaceAllString(repo.Description, `<a href="$0" target="_blank">$0</a>`))
sanitize := func(s string) string {
// TODO(nuss-justin): Improve sanitization. Strip all tags?
ss := html.EscapeString(s)

return fmt.Sprintf(`<a href="%s" target="_blank">%s</a>`, ss, ss)
}
return template.HTML(DescriptionPattern.ReplaceAllStringFunc(repo.Description, sanitize))
}

// IsRepositoryExist returns true if the repository with given name under user has already existed.

Loading…
取消
儲存