summaryrefslogtreecommitdiffstats
path: root/modules/templates
diff options
context:
space:
mode:
authorMorgan Bazalgette <git@howl.moe>2018-02-27 08:09:18 +0100
committerLauris BH <lauris@nix.lv>2018-02-27 09:09:18 +0200
commit535445c32ee730988033728b3b91c4d6f456e08c (patch)
tree34cd5b9807faf01018f47f74a34ed5b584df5158 /modules/templates
parent769ab1e4240f820efdb231832cb7957cb4902807 (diff)
downloadgitea-535445c32ee730988033728b3b91c4d6f456e08c.tar.gz
gitea-535445c32ee730988033728b3b91c4d6f456e08c.zip
Rework special link parsing in the post-processing of markup (#3354)
* Get rid of autolink * autolink in markdown * Replace email addresses with mailto links * better handling of links * Remove autolink.js from footer * Refactor entire html.go * fix some bugs * Make tests green, move what we can to html_internal_test, various other changes to processor logic * Make markdown tests work again This is just a description to allow me to force push in order to restart the drone build. * Fix failing markdown tests in routers/api/v1/misc * Add license headers, log errors, future-proof <body> * fix formatting
Diffstat (limited to 'modules/templates')
-rw-r--r--modules/templates/helper.go42
1 files changed, 17 insertions, 25 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 3f3d6083f2..98900c7538 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -10,6 +10,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "html"
"html/template"
"mime"
"net/url"
@@ -27,7 +28,6 @@ import (
"golang.org/x/net/html/charset"
"golang.org/x/text/transform"
"gopkg.in/editorconfig/editorconfig-core-go.v1"
- "html"
)
// NewFuncMap returns functions for injecting to templates
@@ -280,26 +280,21 @@ func ReplaceLeft(s, old, new string) string {
// RenderCommitMessage renders commit message with XSS-safe and special links.
func RenderCommitMessage(msg, urlPrefix string, metas map[string]string) template.HTML {
- return renderCommitMessage(msg, markup.RenderIssueIndexPatternOptions{
- URLPrefix: urlPrefix,
- Metas: metas,
- })
+ return RenderCommitMessageLink(msg, urlPrefix, "", metas)
}
// RenderCommitMessageLink renders commit message as a XXS-safe link to the provided
// default url, handling for special links.
-func RenderCommitMessageLink(msg, urlPrefix string, urlDefault string, metas map[string]string) template.HTML {
- return renderCommitMessage(msg, markup.RenderIssueIndexPatternOptions{
- DefaultURL: urlDefault,
- URLPrefix: urlPrefix,
- Metas: metas,
- })
-}
-
-func renderCommitMessage(msg string, opts markup.RenderIssueIndexPatternOptions) template.HTML {
+func RenderCommitMessageLink(msg, urlPrefix, urlDefault string, metas map[string]string) template.HTML {
cleanMsg := template.HTMLEscapeString(msg)
- fullMessage := string(markup.RenderIssueIndexPattern([]byte(cleanMsg), opts))
- msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n")
+ // we can safely assume that it will not return any error, since there
+ // shouldn't be any special HTML.
+ fullMessage, err := markup.RenderCommitMessage([]byte(cleanMsg), urlPrefix, urlDefault, metas)
+ if err != nil {
+ log.Error(3, "RenderCommitMessage: %v", err)
+ return ""
+ }
+ msgLines := strings.Split(strings.TrimSpace(string(fullMessage)), "\n")
if len(msgLines) == 0 {
return template.HTML("")
}
@@ -308,16 +303,13 @@ func renderCommitMessage(msg string, opts markup.RenderIssueIndexPatternOptions)
// RenderCommitBody extracts the body of a commit message without its title.
func RenderCommitBody(msg, urlPrefix string, metas map[string]string) template.HTML {
- return renderCommitBody(msg, markup.RenderIssueIndexPatternOptions{
- URLPrefix: urlPrefix,
- Metas: metas,
- })
-}
-
-func renderCommitBody(msg string, opts markup.RenderIssueIndexPatternOptions) template.HTML {
cleanMsg := template.HTMLEscapeString(msg)
- fullMessage := string(markup.RenderIssueIndexPattern([]byte(cleanMsg), opts))
- body := strings.Split(strings.TrimSpace(fullMessage), "\n")
+ fullMessage, err := markup.RenderCommitMessage([]byte(cleanMsg), urlPrefix, "", metas)
+ if err != nil {
+ log.Error(3, "RenderCommitMessage: %v", err)
+ return ""
+ }
+ body := strings.Split(strings.TrimSpace(string(fullMessage)), "\n")
if len(body) == 0 {
return template.HTML("")
}