1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-07-27 17:28:34 +00:00

chore(refactor): partial port of Add API for Variables (#29520)

The commit has, in addition to the implementation of the API, a few
function refactor that are useful in backports.

---

close #27801

---------

Co-authored-by: silverwind <me@silverwind.io>
(cherry picked from commit 62b073e6f31645e446c7e8d6b5a506f61b47924e)

Conflicts:
	- modules/util/util.go
          Trivial resolution, only picking the newly introduced function
	- routers/api/v1/swagger/options.go
          Trivial resolution. We don't have UserBadges, don't pick that part.
	- templates/swagger/v1_json.tmpl
          Regenerated.
(cherry picked from commit 16696a42f5)
This commit is contained in:
sillyguodong 2024-03-29 04:40:35 +08:00 committed by Earl Warren
parent 5b30b7dc6f
commit 0e82cf121d
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
6 changed files with 139 additions and 73 deletions

View file

@ -220,3 +220,12 @@ func Iif[T any](condition bool, trueVal, falseVal T) T {
}
return falseVal
}
func ReserveLineBreakForTextarea(input string) string {
// Since the content is from a form which is a textarea, the line endings are \r\n.
// It's a standard behavior of HTML.
// But we want to store them as \n like what GitHub does.
// And users are unlikely to really need to keep the \r.
// Other than this, we should respect the original content, even leading or trailing spaces.
return strings.ReplaceAll(input, "\r\n", "\n")
}