summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorJason Song <i@wolfogre.com>2023-05-16 14:49:40 +0800
committerGitHub <noreply@github.com>2023-05-16 14:49:40 +0800
commitd81659d03947ac4533099089c5f442437e1d6887 (patch)
tree2bf4ac98a99406d986c87e2032456c21c8d48491 /routers
parent30d922226778a469f01bbb1b933e65428f9266df (diff)
downloadgitea-d81659d03947ac4533099089c5f442437e1d6887.tar.gz
gitea-d81659d03947ac4533099089c5f442437e1d6887.zip
Respect original content when creating secrets (#24745)
Fix #24721. Follow what GitHub does: - Don't trim spaces for secrets. - Newline should be `\n` instead of `\r\n`. Did some tests with: ```yaml name: secrets on: push jobs: show_secrets: runs-on: ubuntu-latest steps: - name: Dump secrets context run: echo '${{ toJSON(secrets) }}' | base64 ``` `AAAAAA`: ```text AAAAAA AAAAAA ``` `BBBBBB`: ```text BBBBBB BBBBBB ``` On GitHub: <img width="675" alt="image" src="https://github.com/go-gitea/gitea/assets/9418365/0ec60652-c2a3-47bb-9f9d-7e81665355a8"> On Gitea (before): <img width="673" alt="image" src="https://github.com/go-gitea/gitea/assets/9418365/cce818bf-5edc-4656-86e1-2c81c304cdb2"> On Gitea (after): <img width="673" alt="image" src="https://github.com/go-gitea/gitea/assets/9418365/0b3b15af-4d48-4bab-a334-4738a1b0eb4a">
Diffstat (limited to 'routers')
-rw-r--r--routers/web/shared/secrets/secrets.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/routers/web/shared/secrets/secrets.go b/routers/web/shared/secrets/secrets.go
index 0e6fa24741..a0d648f908 100644
--- a/routers/web/shared/secrets/secrets.go
+++ b/routers/web/shared/secrets/secrets.go
@@ -5,6 +5,7 @@ package secrets
import (
"net/http"
+ "strings"
"code.gitea.io/gitea/models/db"
secret_model "code.gitea.io/gitea/models/secret"
@@ -27,7 +28,15 @@ func SetSecretsContext(ctx *context.Context, ownerID, repoID int64) {
func PerformSecretsPost(ctx *context.Context, ownerID, repoID int64, redirectURL string) {
form := web.GetForm(ctx).(*forms.AddSecretForm)
- s, err := secret_model.InsertEncryptedSecret(ctx, ownerID, repoID, form.Title, form.Content)
+ content := form.Content
+ // 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.
+ content = strings.ReplaceAll(content, "\r\n", "\n")
+
+ s, err := secret_model.InsertEncryptedSecret(ctx, ownerID, repoID, form.Title, content)
if err != nil {
log.Error("InsertEncryptedSecret: %v", err)
ctx.Flash.Error(ctx.Tr("secrets.creation.failed"))