aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-12-17 22:38:54 +0800
committerGitHub <noreply@github.com>2023-12-17 14:38:54 +0000
commit20929edc9962281e35a81756d76dd1caa5741ff8 (patch)
tree138bbb9c97e609136fe83cf6e5524949218d1e72 /modules/git
parent408a4842240e7dd906e682196bd4254d6c76fcb9 (diff)
downloadgitea-20929edc9962281e35a81756d76dd1caa5741ff8.tar.gz
gitea-20929edc9962281e35a81756d76dd1caa5741ff8.zip
Add option to disable ambiguous unicode characters detection (#28454)
* Close #24483 * Close #28123 * Close #23682 * Close #23149 (maybe more)
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/command.go11
1 files changed, 3 insertions, 8 deletions
diff --git a/modules/git/command.go b/modules/git/command.go
index f095bb18be..9305ef6f92 100644
--- a/modules/git/command.go
+++ b/modules/git/command.go
@@ -14,7 +14,6 @@ import (
"os/exec"
"strings"
"time"
- "unsafe"
"code.gitea.io/gitea/modules/git/internal" //nolint:depguard // only this file can use the internal type CmdArg, other files and packages should use AddXxx functions
"code.gitea.io/gitea/modules/log"
@@ -389,15 +388,11 @@ func (r *runStdError) IsExitCode(code int) bool {
return false
}
-func bytesToString(b []byte) string {
- return *(*string)(unsafe.Pointer(&b)) // that's what Golang's strings.Builder.String() does (go/src/strings/builder.go)
-}
-
// RunStdString runs the command with options and returns stdout/stderr as string. and store stderr to returned error (err combined with stderr).
func (c *Command) RunStdString(opts *RunOpts) (stdout, stderr string, runErr RunStdError) {
stdoutBytes, stderrBytes, err := c.RunStdBytes(opts)
- stdout = bytesToString(stdoutBytes)
- stderr = bytesToString(stderrBytes)
+ stdout = util.UnsafeBytesToString(stdoutBytes)
+ stderr = util.UnsafeBytesToString(stderrBytes)
if err != nil {
return stdout, stderr, &runStdError{err: err, stderr: stderr}
}
@@ -432,7 +427,7 @@ func (c *Command) RunStdBytes(opts *RunOpts) (stdout, stderr []byte, runErr RunS
err := c.Run(newOpts)
stderr = stderrBuf.Bytes()
if err != nil {
- return nil, stderr, &runStdError{err: err, stderr: bytesToString(stderr)}
+ return nil, stderr, &runStdError{err: err, stderr: util.UnsafeBytesToString(stderr)}
}
// even if there is no err, there could still be some stderr output
return stdoutBuf.Bytes(), stderr, nil