Skip to content

Commit 44909f6

Browse files
authored
Fix markup render regression and fix some tests (#32640)
Fix #32639, #32608 (comment) By the way, fix some incorrect SQLs (use single quote but not double quote)
1 parent 5d57c28 commit 44909f6

File tree

6 files changed

+37
-23
lines changed

6 files changed

+37
-23
lines changed

models/activities/action.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -770,15 +770,15 @@ func DeleteIssueActions(ctx context.Context, repoID, issueID, issueIndex int64)
770770
// CountActionCreatedUnixString count actions where created_unix is an empty string
771771
func CountActionCreatedUnixString(ctx context.Context) (int64, error) {
772772
if setting.Database.Type.IsSQLite3() {
773-
return db.GetEngine(ctx).Where(`created_unix = ""`).Count(new(Action))
773+
return db.GetEngine(ctx).Where(`created_unix = ''`).Count(new(Action))
774774
}
775775
return 0, nil
776776
}
777777

778778
// FixActionCreatedUnixString set created_unix to zero if it is an empty string
779779
func FixActionCreatedUnixString(ctx context.Context) (int64, error) {
780780
if setting.Database.Type.IsSQLite3() {
781-
res, err := db.GetEngine(ctx).Exec(`UPDATE action SET created_unix = 0 WHERE created_unix = ""`)
781+
res, err := db.GetEngine(ctx).Exec(`UPDATE action SET created_unix = 0 WHERE created_unix = ''`)
782782
if err != nil {
783783
return 0, err
784784
}

models/activities/action_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func TestConsistencyUpdateAction(t *testing.T) {
256256
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
257257
ID: int64(id),
258258
})
259-
_, err := db.GetEngine(db.DefaultContext).Exec(`UPDATE action SET created_unix = "" WHERE id = ?`, id)
259+
_, err := db.GetEngine(db.DefaultContext).Exec(`UPDATE action SET created_unix = '' WHERE id = ?`, id)
260260
assert.NoError(t, err)
261261
actions := make([]*activities_model.Action, 0, 1)
262262
//

models/issues/label_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func TestDeleteIssueLabel(t *testing.T) {
406406
PosterID: doerID,
407407
IssueID: issueID,
408408
LabelID: labelID,
409-
}, `content=""`)
409+
}, `content=''`)
410410
label = unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: labelID})
411411
assert.EqualValues(t, expectedNumIssues, label.NumIssues)
412412
assert.EqualValues(t, expectedNumClosedIssues, label.NumClosedIssues)

modules/indexer/code/indexer_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222

2323
"github.com/stretchr/testify/assert"
2424
"github.com/stretchr/testify/require"
25-
26-
_ "github.com/mattn/go-sqlite3"
2725
)
2826

2927
type codeSearchResult struct {

routers/api/v1/misc/markup_test.go

+31-17
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,37 @@ import (
77
go_context "context"
88
"io"
99
"net/http"
10+
"os"
1011
"path"
1112
"strings"
1213
"testing"
1314

15+
repo_model "code.gitea.io/gitea/models/repo"
16+
"code.gitea.io/gitea/models/unittest"
1417
"code.gitea.io/gitea/modules/markup"
1518
"code.gitea.io/gitea/modules/setting"
1619
api "code.gitea.io/gitea/modules/structs"
1720
"code.gitea.io/gitea/modules/test"
1821
"code.gitea.io/gitea/modules/web"
22+
context_service "code.gitea.io/gitea/services/context"
1923
"code.gitea.io/gitea/services/contexttest"
2024

2125
"github.com/stretchr/testify/assert"
2226
)
2327

2428
const AppURL = "http://localhost:3000/"
2529

30+
func TestMain(m *testing.M) {
31+
unittest.MainTest(m, &unittest.TestOptions{
32+
FixtureFiles: []string{"repository.yml", "user.yml"},
33+
})
34+
os.Exit(m.Run())
35+
}
36+
2637
func testRenderMarkup(t *testing.T, mode string, wiki bool, filePath, text, expectedBody string, expectedCode int) {
2738
setting.AppURL = AppURL
2839
defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
29-
context := "/gogits/gogs"
40+
context := "/user2/repo1"
3041
if !wiki {
3142
context += path.Join("/src/branch/main", path.Dir(filePath))
3243
}
@@ -38,6 +49,8 @@ func testRenderMarkup(t *testing.T, mode string, wiki bool, filePath, text, expe
3849
FilePath: filePath,
3950
}
4051
ctx, resp := contexttest.MockAPIContext(t, "POST /api/v1/markup")
52+
ctx.Repo = &context_service.Repository{}
53+
ctx.Repo.Repository = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
4154
web.SetForm(ctx, &options)
4255
Markup(ctx)
4356
assert.Equal(t, expectedBody, resp.Body.String())
@@ -48,7 +61,7 @@ func testRenderMarkup(t *testing.T, mode string, wiki bool, filePath, text, expe
4861
func testRenderMarkdown(t *testing.T, mode string, wiki bool, text, responseBody string, responseCode int) {
4962
defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
5063
setting.AppURL = AppURL
51-
context := "/gogits/gogs"
64+
context := "/user2/repo1"
5265
if !wiki {
5366
context += "/src/branch/main"
5467
}
@@ -67,6 +80,7 @@ func testRenderMarkdown(t *testing.T, mode string, wiki bool, text, responseBody
6780
}
6881

6982
func TestAPI_RenderGFM(t *testing.T) {
83+
unittest.PrepareTestEnv(t)
7084
markup.Init(&markup.RenderHelperFuncs{
7185
IsUsernameMentionable: func(ctx go_context.Context, username string) bool {
7286
return username == "r-lyeh"
@@ -82,20 +96,20 @@ func TestAPI_RenderGFM(t *testing.T) {
8296
// rendered
8397
`<p>Wiki! Enjoy :)</p>
8498
<ul>
85-
<li><a href="http://localhost:3000/gogits/gogs/wiki/Links" rel="nofollow">Links, Language bindings, Engine bindings</a></li>
86-
<li><a href="http://localhost:3000/gogits/gogs/wiki/Tips" rel="nofollow">Tips</a></li>
99+
<li><a href="http://localhost:3000/user2/repo1/wiki/Links" rel="nofollow">Links, Language bindings, Engine bindings</a></li>
100+
<li><a href="http://localhost:3000/user2/repo1/wiki/Tips" rel="nofollow">Tips</a></li>
87101
<li>Bezier widget (by <a href="http://localhost:3000/r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="https://github.com/ocornut/imgui/issues/786" rel="nofollow">https://github.com/ocornut/imgui/issues/786</a></li>
88102
</ul>
89103
`,
90104
// Guard wiki sidebar: special syntax
91105
`[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`,
92106
// rendered
93-
`<p><a href="http://localhost:3000/gogits/gogs/wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
107+
`<p><a href="http://localhost:3000/user2/repo1/wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
94108
`,
95109
// special syntax
96110
`[[Name|Link]]`,
97111
// rendered
98-
`<p><a href="http://localhost:3000/gogits/gogs/wiki/Link" rel="nofollow">Name</a></p>
112+
`<p><a href="http://localhost:3000/user2/repo1/wiki/Link" rel="nofollow">Name</a></p>
99113
`,
100114
// empty
101115
``,
@@ -119,8 +133,8 @@ Here are some links to the most important topics. You can find the full list of
119133
<p><strong>Wine Staging</strong> on website <a href="http://wine-staging.com" rel="nofollow">wine-staging.com</a>.</p>
120134
<h2 id="user-content-quick-links">Quick Links</h2>
121135
<p>Here are some links to the most important topics. You can find the full list of pages at the sidebar.</p>
122-
<p><a href="http://localhost:3000/gogits/gogs/wiki/Configuration" rel="nofollow">Configuration</a>
123-
<a href="http://localhost:3000/gogits/gogs/wiki/raw/images/icon-bug.png" rel="nofollow"><img src="http://localhost:3000/gogits/gogs/wiki/raw/images/icon-bug.png" title="icon-bug.png" alt="images/icon-bug.png"/></a></p>
136+
<p><a href="http://localhost:3000/user2/repo1/wiki/Configuration" rel="nofollow">Configuration</a>
137+
<a href="http://localhost:3000/user2/repo1/wiki/raw/images/icon-bug.png" rel="nofollow"><img src="http://localhost:3000/user2/repo1/wiki/raw/images/icon-bug.png" title="icon-bug.png" alt="images/icon-bug.png"/></a></p>
124138
`,
125139
}
126140

@@ -143,20 +157,20 @@ Here are some links to the most important topics. You can find the full list of
143157
}
144158

145159
input := "[Link](test.md)\n![Image](image.png)"
146-
testRenderMarkdown(t, "gfm", false, input, `<p><a href="http://localhost:3000/gogits/gogs/src/branch/main/test.md" rel="nofollow">Link</a>
147-
<a href="http://localhost:3000/gogits/gogs/media/branch/main/image.png" target="_blank" rel="nofollow noopener"><img src="http://localhost:3000/gogits/gogs/media/branch/main/image.png" alt="Image"/></a></p>
160+
testRenderMarkdown(t, "gfm", false, input, `<p><a href="http://localhost:3000/user2/repo1/src/branch/main/test.md" rel="nofollow">Link</a>
161+
<a href="http://localhost:3000/user2/repo1/media/branch/main/image.png" target="_blank" rel="nofollow noopener"><img src="http://localhost:3000/user2/repo1/media/branch/main/image.png" alt="Image"/></a></p>
148162
`, http.StatusOK)
149163

150-
testRenderMarkdown(t, "gfm", false, input, `<p><a href="http://localhost:3000/gogits/gogs/src/branch/main/test.md" rel="nofollow">Link</a>
151-
<a href="http://localhost:3000/gogits/gogs/media/branch/main/image.png" target="_blank" rel="nofollow noopener"><img src="http://localhost:3000/gogits/gogs/media/branch/main/image.png" alt="Image"/></a></p>
164+
testRenderMarkdown(t, "gfm", false, input, `<p><a href="http://localhost:3000/user2/repo1/src/branch/main/test.md" rel="nofollow">Link</a>
165+
<a href="http://localhost:3000/user2/repo1/media/branch/main/image.png" target="_blank" rel="nofollow noopener"><img src="http://localhost:3000/user2/repo1/media/branch/main/image.png" alt="Image"/></a></p>
152166
`, http.StatusOK)
153167

154-
testRenderMarkup(t, "gfm", false, "", input, `<p><a href="http://localhost:3000/gogits/gogs/src/branch/main/test.md" rel="nofollow">Link</a>
155-
<a href="http://localhost:3000/gogits/gogs/media/branch/main/image.png" target="_blank" rel="nofollow noopener"><img src="http://localhost:3000/gogits/gogs/media/branch/main/image.png" alt="Image"/></a></p>
168+
testRenderMarkup(t, "gfm", false, "", input, `<p><a href="http://localhost:3000/user2/repo1/src/branch/main/test.md" rel="nofollow">Link</a>
169+
<a href="http://localhost:3000/user2/repo1/media/branch/main/image.png" target="_blank" rel="nofollow noopener"><img src="http://localhost:3000/user2/repo1/media/branch/main/image.png" alt="Image"/></a></p>
156170
`, http.StatusOK)
157171

158-
testRenderMarkup(t, "file", false, "path/new-file.md", input, `<p><a href="http://localhost:3000/gogits/gogs/src/branch/main/path/test.md" rel="nofollow">Link</a>
159-
<a href="http://localhost:3000/gogits/gogs/media/branch/main/path/image.png" target="_blank" rel="nofollow noopener"><img src="http://localhost:3000/gogits/gogs/media/branch/main/path/image.png" alt="Image"/></a></p>
172+
testRenderMarkup(t, "file", false, "path/new-file.md", input, `<p><a href="http://localhost:3000/user2/repo1/src/branch/main/path/test.md" rel="nofollow">Link</a>
173+
<a href="http://localhost:3000/user2/repo1/media/branch/main/path/image.png" target="_blank" rel="nofollow noopener"><img src="http://localhost:3000/user2/repo1/media/branch/main/path/image.png" alt="Image"/></a></p>
160174
`, http.StatusOK)
161175

162176
testRenderMarkup(t, "file", false, "path/test.unknown", "## Test", "unsupported file to render: \"path/test.unknown\"\n", http.StatusUnprocessableEntity)
@@ -186,7 +200,7 @@ func TestAPI_RenderSimple(t *testing.T) {
186200
options := api.MarkdownOption{
187201
Mode: "markdown",
188202
Text: "",
189-
Context: "/gogits/gogs",
203+
Context: "/user2/repo1",
190204
}
191205
ctx, resp := contexttest.MockAPIContext(t, "POST /api/v1/markdown")
192206
for i := 0; i < len(simpleCases); i += 2 {

routers/common/markup.go

+2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ func RenderMarkup(ctx *context.Base, ctxRepo *context.Repository, mode, text, ur
7777
rctx = rctx.WithMarkupType(markdown.MarkupName)
7878
case "comment":
7979
rctx = renderhelper.NewRenderContextRepoComment(ctx, repoModel, renderhelper.RepoCommentOptions{DeprecatedOwnerName: repoOwnerName, DeprecatedRepoName: repoName})
80+
rctx = rctx.WithMarkupType(markdown.MarkupName)
8081
case "wiki":
8182
rctx = renderhelper.NewRenderContextRepoWiki(ctx, repoModel, renderhelper.RepoWikiOptions{DeprecatedOwnerName: repoOwnerName, DeprecatedRepoName: repoName})
83+
rctx = rctx.WithMarkupType(markdown.MarkupName)
8284
case "file":
8385
rctx = renderhelper.NewRenderContextRepoFile(ctx, repoModel, renderhelper.RepoFileOptions{
8486
DeprecatedOwnerName: repoOwnerName, DeprecatedRepoName: repoName,

0 commit comments

Comments
 (0)