diff options
author | Unknwon <joe2010xtmf@163.com> | 2015-01-30 18:05:20 -0500 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2015-01-30 18:05:20 -0500 |
commit | 37fcc8daf2d7d86e4d0f8baaeab0b2e11e5ec8d0 (patch) | |
tree | 701088978b660c46cdb463e0f191aed8adb01195 /modules | |
parent | 9803f84c883c372cca9ed5859cbf8f930af63d51 (diff) | |
download | gitea-37fcc8daf2d7d86e4d0f8baaeab0b2e11e5ec8d0.tar.gz gitea-37fcc8daf2d7d86e4d0f8baaeab0b2e11e5ec8d0.zip |
modules/base: add RenderCommitMessage with XSS-safe and special links
- update russian locale
Diffstat (limited to 'modules')
-rw-r--r-- | modules/base/markdown.go | 2 | ||||
-rw-r--r-- | modules/base/template.go | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/modules/base/markdown.go b/modules/base/markdown.go index b2f94c480b..2cd3617a8f 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -103,7 +103,7 @@ var ( MentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`) commitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`) issueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`) - issueIndexPattern = regexp.MustCompile(`#[0-9]+`) + issueIndexPattern = regexp.MustCompile(`( |^)#[0-9]+`) sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{40}\b`) ) diff --git a/modules/base/template.go b/modules/base/template.go index 829999d1c9..34caa4552b 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -90,6 +90,11 @@ func ToUtf8(content string) string { return res } +// RenderCommitMessage renders commit message with XSS-safe and special links. +func RenderCommitMessage(msg, urlPrefix string) template.HTML { + return template.HTML(string(RenderIssueIndexPattern([]byte(template.HTMLEscapeString(msg)), urlPrefix))) +} + var mailDomains = map[string]string{ "gmail.com": "gmail.com", } @@ -163,6 +168,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ "EscapePound": func(str string) string { return strings.Replace(str, "#", "%23", -1) }, + "RenderCommitMessage": RenderCommitMessage, } type Actioner interface { |