diff options
author | Unknwon <u@gogs.io> | 2016-12-23 19:00:24 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-12-23 19:00:24 -0500 |
commit | eb79532812fb2d19e416faee91e64a190b702e7c (patch) | |
tree | 4980386a999b8034aa07a924bb4a8efc7b09683d /modules/markdown/markdown.go | |
parent | 5feb68a5892794a51e29c0d4db32297c98b3f943 (diff) |
Minor fix for PR #3436
Diffstat (limited to 'modules/markdown/markdown.go')
-rw-r--r-- | modules/markdown/markdown.go | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/modules/markdown/markdown.go b/modules/markdown/markdown.go index d8e6cfc5..4fbd5a3d 100644 --- a/modules/markdown/markdown.go +++ b/modules/markdown/markdown.go @@ -91,7 +91,7 @@ var ( IssueAlphanumericPattern = regexp.MustCompile(`( |^|\()[A-Z]{1,10}-[1-9][0-9]*\b`) // CrossReferenceIssueNumericPattern matches string that references a numeric issue in a difference repository // e.g. gogits/gogs#12345 - CrossReferenceIssueNumericPattern = regexp.MustCompile(`( |^)[0-9a-zA-Z]+/[0-9a-zA-Z]+#[0-9]+\b`) + CrossReferenceIssueNumericPattern = regexp.MustCompile(`( |^)[0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+#[0-9]+\b`) // Sha1CurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae // FIXME: this pattern matches pure numbers as well, right now we do a hack to check in RenderSha1CurrentPattern @@ -158,16 +158,16 @@ func (r *Renderer) AutoLink(out *bytes.Buffer, link []byte, kind int) { j = len(m) } - issue := string(m[i+7 : j]) - fullRepoUrl := setting.AppUrl + strings.TrimPrefix(r.urlPrefix, "/") + index := string(m[i+7 : j]) + fullRepoURL := setting.AppUrl + strings.TrimPrefix(r.urlPrefix, "/") var link string - if strings.HasPrefix(string(m), fullRepoUrl) { + if strings.HasPrefix(string(m), fullRepoURL) { // Use a short issue reference if the URL refers to this repository - link = fmt.Sprintf(`<a href="%s">#%s</a>`, m, issue) + link = fmt.Sprintf(`<a href="%s">#%s</a>`, m, index) } else { // Use a cross-repository issue reference if the URL refers to a different repository repo := string(m[len(setting.AppUrl) : i-1]) - link = fmt.Sprintf(`<a href="%s">%s#%s</a>`, m, repo, issue) + link = fmt.Sprintf(`<a href="%s">%s#%s</a>`, m, repo, index) } out.WriteString(link) return @@ -284,10 +284,11 @@ func RenderCrossReferenceIssueIndexPattern(rawBytes []byte, urlPrefix string, me m = m[1:] // ignore leading space or opening parentheses } - repo := string(bytes.Split(m, []byte("#"))[0]) - issue := string(bytes.Split(m, []byte("#"))[1]) + fields := bytes.Split(m, []byte("#"))[0] + repo := string(fields[0]) + index := string(fields[1]) - link := fmt.Sprintf(`<a href="%s%s/issues/%s">%s</a>`, setting.AppUrl, repo, issue, m) + link := fmt.Sprintf(`<a href="%s%s/issues/%s">%s</a>`, setting.AppUrl, repo, index, m) rawBytes = bytes.Replace(rawBytes, m, []byte(link), 1) } return rawBytes |