Skip to content

Commit 2bf3723

Browse files
author
Earl Warren
committed
Merge pull request '[v7.0/forgejo] [BUG] Fix crash in issue forms' (go-gitea#3036) from bp-v7.0/forgejo-b0cd0eb into v7.0/forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3036 Reviewed-by: Earl Warren <[email protected]>
2 parents fbaebbd + aefdf17 commit 2bf3723

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

modules/markup/html.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,9 +1065,12 @@ func filePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
10651065

10661066
next := node.NextSibling
10671067
for node != nil && node != next {
1068-
locale, ok := ctx.Ctx.Value(translation.ContextKey).(translation.Locale)
1069-
if !ok {
1070-
locale = translation.NewLocale("en-US")
1068+
locale := translation.NewLocale("en-US")
1069+
if ctx.Ctx != nil {
1070+
ctxLocale, ok := ctx.Ctx.Value(translation.ContextKey).(translation.Locale)
1071+
if ok {
1072+
locale = ctxLocale
1073+
}
10711074
}
10721075

10731076
preview := NewFilePreview(ctx, node, locale)

tests/integration/issue_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ import (
1818
"code.gitea.io/gitea/models/db"
1919
issues_model "code.gitea.io/gitea/models/issues"
2020
repo_model "code.gitea.io/gitea/models/repo"
21+
unit_model "code.gitea.io/gitea/models/unit"
2122
"code.gitea.io/gitea/models/unittest"
2223
user_model "code.gitea.io/gitea/models/user"
2324
"code.gitea.io/gitea/modules/indexer/issues"
2425
"code.gitea.io/gitea/modules/references"
2526
"code.gitea.io/gitea/modules/setting"
2627
api "code.gitea.io/gitea/modules/structs"
2728
"code.gitea.io/gitea/modules/test"
29+
files_service "code.gitea.io/gitea/services/repository/files"
2830
"code.gitea.io/gitea/tests"
2931

3032
"github.com/PuerkitoBio/goquery"
@@ -815,3 +817,52 @@ func TestIssueFilterNoFollow(t *testing.T) {
815817
assert.Equal(t, "nofollow", rel)
816818
})
817819
}
820+
821+
func TestIssueForm(t *testing.T) {
822+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
823+
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
824+
session := loginUser(t, user2.Name)
825+
repo, _, f := CreateDeclarativeRepo(t, user2, "",
826+
[]unit_model.Type{unit_model.TypeCode, unit_model.TypeIssues}, nil,
827+
[]*files_service.ChangeRepoFile{
828+
{
829+
Operation: "create",
830+
TreePath: ".forgejo/issue_template/test.yaml",
831+
ContentReader: strings.NewReader(`name: Test
832+
about: Hello World
833+
body:
834+
- type: checkboxes
835+
id: test
836+
attributes:
837+
label: Test
838+
options:
839+
- label: This is a label
840+
`),
841+
},
842+
},
843+
)
844+
defer f()
845+
846+
t.Run("Choose list", func(t *testing.T) {
847+
defer tests.PrintCurrentTest(t)()
848+
849+
req := NewRequest(t, "GET", repo.Link()+"/issues/new/choose")
850+
resp := session.MakeRequest(t, req, http.StatusOK)
851+
htmlDoc := NewHTMLParser(t, resp.Body)
852+
853+
htmlDoc.AssertElement(t, "a[href$='/issues/new?template=.forgejo%2fissue_template%2ftest.yaml']", true)
854+
})
855+
856+
t.Run("Issue template", func(t *testing.T) {
857+
defer tests.PrintCurrentTest(t)()
858+
859+
req := NewRequest(t, "GET", repo.Link()+"/issues/new?template=.forgejo%2fissue_template%2ftest.yaml")
860+
resp := session.MakeRequest(t, req, http.StatusOK)
861+
htmlDoc := NewHTMLParser(t, resp.Body)
862+
863+
htmlDoc.AssertElement(t, "#new-issue .field .ui.checkbox input[name='form-field-test-0']", true)
864+
checkboxLabel := htmlDoc.Find("#new-issue .field .ui.checkbox label").Text()
865+
assert.Contains(t, checkboxLabel, "This is a label")
866+
})
867+
})
868+
}

0 commit comments

Comments
 (0)