diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 85354784d4..fca210bb10 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -16,6 +16,7 @@ import (
"net/url"
"os"
"os/exec"
+ "regexp"
"sort"
"strconv"
"strings"
@@ -180,55 +181,61 @@ var (
removedCodePrefix = []byte(``)
codeTagSuffix = []byte(``)
)
+var addSpanRegex = regexp.MustCompile(` 0 {
+ diffs[i].Text = addSpan + diffs[i].Text
+ addSpan = ""
}
- if strings.HasSuffix(diffs[i].Text, " 0 {
+ diffs[i].Text = addSpan + diffs[i].Text
+ addSpan = ""
}
// Print existing closing span first before opening added-code span so it doesn't unintentionally close it
if strings.HasPrefix(diffs[i].Text, "") {
buf.WriteString("")
diffs[i].Text = strings.TrimPrefix(diffs[i].Text, "")
}
- if strings.HasSuffix(diffs[i].Text, " 0 {
+ diffs[i].Text = addSpan + diffs[i].Text
+ addSpan = ""
}
if strings.HasPrefix(diffs[i].Text, "") {
buf.WriteString("")
diffs[i].Text = strings.TrimPrefix(diffs[i].Text, "")
}
- if strings.HasSuffix(diffs[i].Text, " || r.GuessLanguage)"},
{Type: dmp.DiffEqual, Text: " {"},
}, DiffLineAdd))
+
+ assertEqual(t, "tagURL := fmt.Sprintf("## [%s](%s/%s/%s/%s?q=&type=all&state=closed&milestone=%d) - %s", ge.Milestone\", ge.BaseURL, ge.Owner, ge.Repo, from, milestoneID, time.Now().Format("2006-01-02"))", diffToHTML("", []dmp.Diff{
+ {Type: dmp.DiffEqual, Text: "tagURL := fmt.Sprintf("## [%s](%s/%s/%s/%s?q=&type=all&state=closed&milestone=%d) - %s", ge.Milestone\""},
+ {Type: dmp.DiffInsert, Text: "f\">getGiteaTagURL(client"},
+ {Type: dmp.DiffEqual, Text: ", ge.BaseURL, ge.Owner, ge.Repo, "},
+ {Type: dmp.DiffDelete, Text: "from, milestoneID, time.Now().Format("2006-01-02")"},
+ {Type: dmp.DiffInsert, Text: "ge.Milestone, from, milestoneID"},
+ {Type: dmp.DiffEqual, Text: ")"},
+ }, DiffLineDel))
}
func TestParsePatch(t *testing.T) {