feat: strip newlines on og image rendering (#10914)

Replace newlines from the repo description with spaces to match in-app
rendering.

Related issue: #10823

## 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...
  - [ ] in their respective `*_test.go` for unit tests.
  - [ ] 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

- [x] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change.
- [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change.

*The decision if the pull request will be shown in the release notes is up to the mergers / release team.*

The content of the `release-notes/<pull request number>.md` file will serve as the basis for the release notes. If the file does not exist, the title of the pull request will be used instead.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10914
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Co-authored-by: Enrique Sanchez Cardoso <enriqueesanchz@gmail.com>
Co-committed-by: Enrique Sanchez Cardoso <enriqueesanchz@gmail.com>
This commit is contained in:
Enrique Sanchez Cardoso 2026-01-19 18:41:20 +01:00 committed by Mathieu Fenniak
parent 70035bc654
commit 7f22f525fc

View file

@ -152,7 +152,13 @@ func drawRepoSummaryCard(ctx *context.Context, repo *repo_model.Repository) (*ca
}
issueDescription.SetMargin(10)
_, err = issueDescription.DrawText(repo.Description, color.Gray{128}, 36, card.Top, card.Left)
// Replace new lines with spaces to match repo description in-app rendering
issueDescriptionText := strings.NewReplacer(
"\r\n", " ",
"\r", " ",
"\n", " ",
).Replace(repo.Description)
_, err = issueDescription.DrawText(issueDescriptionText, color.Gray{128}, 36, card.Top, card.Left)
if err != nil {
return nil, err
}