@@ -5,6 +5,7 @@ package secrets
5
5
6
6
import (
7
7
"net/http"
8
+ "strings"
8
9
9
10
"code.gitea.io/gitea/models/db"
10
11
secret_model "code.gitea.io/gitea/models/secret"
@@ -27,7 +28,15 @@ func SetSecretsContext(ctx *context.Context, ownerID, repoID int64) {
27
28
func PerformSecretsPost (ctx * context.Context , ownerID , repoID int64 , redirectURL string ) {
28
29
form := web .GetForm (ctx ).(* forms.AddSecretForm )
29
30
30
- s , err := secret_model .InsertEncryptedSecret (ctx , ownerID , repoID , form .Title , form .Content )
31
+ content := form .Content
32
+ // Since the content is from a form which is a textarea, the line endings are \r\n.
33
+ // It's a standard behavior of HTML.
34
+ // But we want to store them as \n like what GitHub does.
35
+ // And users are unlikely to really need to keep the \r.
36
+ // Other than this, we should respect the original content, even leading or trailing spaces.
37
+ content = strings .ReplaceAll (content , "\r \n " , "\n " )
38
+
39
+ s , err := secret_model .InsertEncryptedSecret (ctx , ownerID , repoID , form .Title , content )
31
40
if err != nil {
32
41
log .Error ("InsertEncryptedSecret: %v" , err )
33
42
ctx .Flash .Error (ctx .Tr ("secrets.creation.failed" ))
0 commit comments