Skip to content

Commit c83bc55

Browse files
zeripathlafriks
andauthored
TrimSpace when reading InternalToken from a file (go-gitea#11502) (go-gitea#11524)
InternalTokens are fixed as alphanum strings therefore TrimSpace from these. Also use isatty to not add a terminal newline when redirecting generate. Fix go-gitea#11498 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: Lauris BH <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent 09cc639 commit c83bc55

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

cmd/generate.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ package cmd
77

88
import (
99
"fmt"
10+
"os"
1011

1112
"code.gitea.io/gitea/modules/generate"
1213

14+
"github.com/mattn/go-isatty"
1315
"github.com/urfave/cli"
1416
)
1517

@@ -59,7 +61,12 @@ func runGenerateInternalToken(c *cli.Context) error {
5961
return err
6062
}
6163

62-
fmt.Printf("%s\n", internalToken)
64+
fmt.Printf("%s", internalToken)
65+
66+
if isatty.IsTerminal(os.Stdout.Fd()) {
67+
fmt.Printf("\n")
68+
}
69+
6370
return nil
6471
}
6572

@@ -69,7 +76,12 @@ func runGenerateLfsJwtSecret(c *cli.Context) error {
6976
return err
7077
}
7178

72-
fmt.Printf("%s\n", JWTSecretBase64)
79+
fmt.Printf("%s", JWTSecretBase64)
80+
81+
if isatty.IsTerminal(os.Stdout.Fd()) {
82+
fmt.Printf("\n")
83+
}
84+
7385
return nil
7486
}
7587

@@ -79,6 +91,11 @@ func runGenerateSecretKey(c *cli.Context) error {
7991
return err
8092
}
8193

82-
fmt.Printf("%s\n", secretKey)
94+
fmt.Printf("%s", secretKey)
95+
96+
if isatty.IsTerminal(os.Stdout.Fd()) {
97+
fmt.Printf("\n")
98+
}
99+
83100
return nil
84101
}

modules/setting/setting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ func loadInternalToken(sec *ini.Section) string {
10691069
return token
10701070
}
10711071

1072-
return string(buf)
1072+
return strings.TrimSpace(string(buf))
10731073
default:
10741074
log.Fatal("Unsupported URI-Scheme %q (INTERNAL_TOKEN_URI = %q)", tempURI.Scheme, uri)
10751075
}

0 commit comments

Comments
 (0)