mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-31 14:36:47 +00:00
fix: prevent user-entered text with | characters from being truncated in activity feed (#8844)
Prevents a variety of user-entered texts that can contain `|` characters from being truncated in the activity feed, affecting: issue & PR titles, comment content, review comments, and review dismissal comments. Where `action.content` was containing a pipe-separated list of UI data fields before, it now uses a JSON-encoded string array. The old format is still supported for reading from the feed. In some places where `action.content` was not using this format, or where user-generated text was not inserted, the old format is retained. Fixes part of the cause behind #8781, allowing small mermaid graphs to be rendered in the feed (for now...) --  ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8844 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
This commit is contained in:
parent
f1cfd152e2
commit
1f2bbbd4aa
6 changed files with 140 additions and 14 deletions
|
@ -308,14 +308,69 @@ func TestDeleteIssueActions(t *testing.T) {
|
|||
})
|
||||
require.NoError(t, err)
|
||||
err = db.Insert(db.DefaultContext, &activities_model.Action{
|
||||
OpType: activities_model.ActionCreateIssue,
|
||||
RepoID: issue.RepoID,
|
||||
OpType: activities_model.ActionCreateIssue,
|
||||
RepoID: issue.RepoID,
|
||||
// Older Content format...
|
||||
Content: fmt.Sprintf("%d|content...", issue.Index),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = db.Insert(db.DefaultContext, &activities_model.Action{
|
||||
OpType: activities_model.ActionCreateIssue,
|
||||
RepoID: issue.RepoID,
|
||||
// JSON-encoded Content format...
|
||||
Content: fmt.Sprintf("[\"%d\",\"content...\"]", issue.Index),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// assert that the actions exist, then delete them
|
||||
unittest.AssertCount(t, &activities_model.Action{}, 2)
|
||||
unittest.AssertCount(t, &activities_model.Action{}, 3)
|
||||
require.NoError(t, activities_model.DeleteIssueActions(db.DefaultContext, issue.RepoID, issue.ID, issue.Index))
|
||||
unittest.AssertCount(t, &activities_model.Action{}, 0)
|
||||
}
|
||||
|
||||
func TestGetIssueInfos(t *testing.T) {
|
||||
tt := []struct {
|
||||
content string
|
||||
field1 string
|
||||
field2 string
|
||||
field3 string
|
||||
}{
|
||||
{
|
||||
content: "4|",
|
||||
field1: "4",
|
||||
},
|
||||
{
|
||||
content: "2|docs: Add README w/ template sections",
|
||||
field1: "2",
|
||||
field2: "docs: Add README w/ template sections",
|
||||
},
|
||||
{
|
||||
content: "2|docs: Add README w/ template sections|Some comment...",
|
||||
field1: "2",
|
||||
field2: "docs: Add README w/ template sections",
|
||||
field3: "Some comment...",
|
||||
},
|
||||
{
|
||||
content: "[\"4\"]",
|
||||
field1: "4",
|
||||
},
|
||||
{
|
||||
content: "[\"2\", \"docs: Add README w/ | template sections\"]",
|
||||
field1: "2",
|
||||
field2: "docs: Add README w/ | template sections",
|
||||
},
|
||||
{
|
||||
content: "[\"2\", \"docs: Add README w/ | template sections\", \"Some | comment...\"]",
|
||||
field1: "2",
|
||||
field2: "docs: Add README w/ | template sections",
|
||||
field3: "Some | comment...",
|
||||
},
|
||||
}
|
||||
for _, test := range tt {
|
||||
action := &activities_model.Action{Content: test.content}
|
||||
issueInfos := action.GetIssueInfos()
|
||||
assert.Equal(t, test.field1, issueInfos[0])
|
||||
assert.Equal(t, test.field2, issueInfos[1])
|
||||
assert.Equal(t, test.field3, issueInfos[2])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue