mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add API for Variables
(#29520)
close #27801 --------- Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -221,3 +221,12 @@ func IfZero[T comparable](v, def T) T {
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
@@ -235,3 +235,8 @@ func TestToPointer(t *testing.T) {
|
||||
val123 := 123
|
||||
assert.False(t, &val123 == ToPointer(val123))
|
||||
}
|
||||
|
||||
func TestReserveLineBreakForTextarea(t *testing.T) {
|
||||
assert.Equal(t, ReserveLineBreakForTextarea("test\r\ndata"), "test\ndata")
|
||||
assert.Equal(t, ReserveLineBreakForTextarea("test\r\ndata\r\n"), "test\ndata\n")
|
||||
}
|
||||
|
Reference in New Issue
Block a user