Skip to content

Commit dc4f98e

Browse files
committed
fix lint
1 parent dc506f2 commit dc4f98e

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

routers/api/v1/misc/markup_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
const AppURL = "http://localhost:3000/"
2323

2424
func testRenderMarkup(t *testing.T, mode string, wiki bool, filePath, text, expectedBody string, expectedCode int) {
25-
t.Helper()
2625
setting.AppURL = AppURL
2726
context := "/gogits/gogs"
2827
if !wiki {
@@ -44,7 +43,6 @@ func testRenderMarkup(t *testing.T, mode string, wiki bool, filePath, text, expe
4443
}
4544

4645
func testRenderMarkdown(t *testing.T, mode string, wiki bool, text, responseBody string, responseCode int) {
47-
t.Helper()
4846
setting.AppURL = AppURL
4947
context := "/gogits/gogs"
5048
if !wiki {

routers/common/markup.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package common
66

77
import (
8-
"code.gitea.io/gitea/modules/setting"
98
"fmt"
109
"net/http"
1110
"strings"
@@ -14,23 +13,24 @@ import (
1413
"code.gitea.io/gitea/modules/httplib"
1514
"code.gitea.io/gitea/modules/markup"
1615
"code.gitea.io/gitea/modules/markup/markdown"
16+
"code.gitea.io/gitea/modules/setting"
1717
"code.gitea.io/gitea/services/context"
1818
)
1919

2020
// RenderMarkup renders markup text for the /markup and /markdown endpoints
21-
func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, pathContext, filePath string, wiki bool) {
22-
// pathContext format is /subpath/{user}/{repo}/src/{branch, commit, tag}/{identifier/path}
21+
func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, urlPathContext, filePath string, wiki bool) {
22+
// urlPathContext format is /subpath/{user}/{repo}/src/{branch, commit, tag}/{identifier/path}
2323
// for example: "/gitea/owner/repo/src/branch/features/feat-123"
2424

2525
// filePath is the path of the file to render if the end user is trying to preview a repo file (mode == "file")
2626
// for example, when previewing file ""/gitea/owner/repo/src/branch/features/feat-123/doc/CHANGE.md", then filePath is "doc/CHANGE.md"
2727
// and filePath will be used as RenderContext.RelativePath
2828

29-
markupType := ""
30-
relativePath := ""
29+
var markupType, relativePath string
30+
3131
links := markup.Links{AbsolutePrefix: true}
32-
if pathContext != "" {
33-
links.Base = fmt.Sprintf("%s%s", httplib.GuessCurrentHostURL(ctx), pathContext)
32+
if urlPathContext != "" {
33+
links.Base = fmt.Sprintf("%s%s", httplib.GuessCurrentHostURL(ctx), urlPathContext)
3434
}
3535

3636
switch mode {
@@ -57,13 +57,12 @@ func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, pathC
5757
return
5858
}
5959

60-
fields := strings.SplitN(strings.TrimPrefix(pathContext, setting.AppSubURL+"/"), "/", 5)
60+
fields := strings.SplitN(strings.TrimPrefix(urlPathContext, setting.AppSubURL+"/"), "/", 5)
6161
if len(fields) == 5 && fields[2] == "src" && fields[3] == "branch" {
62-
links = markup.Links{
63-
AbsolutePrefix: true,
64-
Base: fmt.Sprintf("%s%s/%s", httplib.GuessCurrentAppURL(ctx), fields[0], fields[1]), // provides "https://host/subpath/{user}/{repo}"
65-
BranchPath: strings.Join(fields[3:], "/"),
66-
}
62+
// they provide "https://host/subpath/{user}/{repo}" and "branch/features/feat-12" for links
63+
absoluteBasePrefix := fmt.Sprintf("%s%s/%s", httplib.GuessCurrentAppURL(ctx), fields[0], fields[1])
64+
refPath := strings.Join(fields[3:], "/")
65+
links = markup.Links{AbsolutePrefix: true, Base: absoluteBasePrefix, BranchPath: refPath}
6766
}
6867

6968
meta := map[string]string{}

0 commit comments

Comments
 (0)