diff --git a/models/issues/issue.go b/models/issues/issue.go index f04a4ad5c7..f7379b7e0c 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -153,8 +153,8 @@ type Issue struct { } var ( - issueTasksPat = regexp.MustCompile(`(^\s*[-*]\s\[[\sxX]\]\s.)|(\n\s*[-*]\s\[[\sxX]\]\s.)`) - issueTasksDonePat = regexp.MustCompile(`(^\s*[-*]\s\[[xX]\]\s.)|(\n\s*[-*]\s\[[xX]\]\s.)`) + issueTasksPat = regexp.MustCompile(`(^|\n)\s*[-*]\s*\[[\sxX]\]`) + issueTasksDonePat = regexp.MustCompile(`(^|\n)\s*[-*]\s*\[[xX]\]`) ) // IssueIndex represents the issue index table diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index ccae0b00ea..bf05c3c0a6 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -10,6 +10,7 @@ import ( "net/http" "net/url" "path" + "regexp" "strconv" "strings" "testing" @@ -236,9 +237,13 @@ func testNewIssue(t *testing.T, session *TestSession, user, repo, title, content htmlDoc = NewHTMLParser(t, resp.Body) val := htmlDoc.doc.Find("#issue-title-display").Text() assert.Contains(t, val, title) - val = htmlDoc.doc.Find(".comment .render-content p").First().Text() - assert.Equal(t, content, val) - + // test for first line only and if it contains only letters and spaces + contentFirstLine := strings.Split(content, "\n")[0] + patNotLetterOrSpace := regexp.MustCompile(`[^\p{L}\s]`) + if len(contentFirstLine) != 0 && !patNotLetterOrSpace.MatchString(contentFirstLine) { + val = htmlDoc.doc.Find(".comment .render-content p").First().Text() + assert.Equal(t, contentFirstLine, val) + } return issueURL } @@ -281,6 +286,50 @@ func TestNewIssue(t *testing.T) { testNewIssue(t, session, "user2", "repo1", "Title", "Description") } +func TestIssueCheckboxes(t *testing.T) { + defer tests.PrepareTestEnv(t)() + session := loginUser(t, "user2") + issueURL := testNewIssue(t, session, "user2", "repo1", "Title", `- [x] small x +- [X] capital X +- [ ] empty + - [x]x without gap + - [ ]empty without gap +- [x] +x on new line +- [ ] +empty on new line + - [ ] tabs instead of spaces +Description`) + req := NewRequest(t, "GET", issueURL) + resp := session.MakeRequest(t, req, http.StatusOK) + issueContent := NewHTMLParser(t, resp.Body).doc.Find(".comment .render-content").First() + isCheckBox := func(i int, s *goquery.Selection) bool { + typeVal, typeExists := s.Attr("type") + return typeExists && typeVal == "checkbox" + } + isChecked := func(i int, s *goquery.Selection) bool { + _, checkedExists := s.Attr("checked") + return checkedExists + } + checkBoxes := issueContent.Find("input").FilterFunction(isCheckBox) + assert.Equal(t, 8, checkBoxes.Length()) + assert.Equal(t, 4, checkBoxes.FilterFunction(isChecked).Length()) + + // Issues list should show the correct numbers of checked and total checkboxes + repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1") + assert.NoError(t, err) + req = NewRequestf(t, "GET", "%s/issues", repo.Link()) + resp = MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + issuesSelection := htmlDoc.Find("#issue-list .flex-item") + assert.Equal(t, "4 / 8", strings.TrimSpace(issuesSelection.Find(".checklist").Text())) + value, _ := issuesSelection.Find("progress").Attr("value") + vmax, _ := issuesSelection.Find("progress").Attr("max") + assert.Equal(t, "4", value) + assert.Equal(t, "8", vmax) +} + func TestIssueDependencies(t *testing.T) { defer tests.PrepareTestEnv(t)() diff --git a/web_src/js/markup/tasklist.js b/web_src/js/markup/tasklist.js index a40b5e4abd..375810dc2f 100644 --- a/web_src/js/markup/tasklist.js +++ b/web_src/js/markup/tasklist.js @@ -32,11 +32,11 @@ export function initMarkupTasklist() { const buffer = encoder.encode(oldContent); // Indexes may fall off the ends and return undefined. if (buffer[position - 1] !== '['.codePointAt(0) || - buffer[position] !== ' '.codePointAt(0) && buffer[position] !== 'x'.codePointAt(0) || + buffer[position] !== ' '.codePointAt(0) && buffer[position] !== 'x'.codePointAt(0) && buffer[position] !== 'X'.codePointAt(0) || buffer[position + 1] !== ']'.codePointAt(0)) { // Position is probably wrong. Revert and don't allow change. checkbox.checked = !checkbox.checked; - throw new Error(`Expected position to be space or x and surrounded by brackets, but it's not: position=${position}`); + throw new Error(`Expected position to be space, x or X and surrounded by brackets, but it's not: position=${position}`); } buffer.set(encoder.encode(checkboxCharacter), position); const newContent = new TextDecoder().decode(buffer);