Open jericjan opened 1 year ago
Hello @jericjan 👋🏻
I cannot reproduce the issue with lazygit v0.40.2 on Linux, but the escaping mechanism differs from one OS to another:
commit=v0.40.2, build date=2023-08-12T17:47:33Z, build source=binaryRelease, version=0.40.2, os=linux, arch=amd64, git version=2.42.0
I don't have a Windows machine at the moment, but I'm wondering if applying something similar to this patch would solve the issue 🤔
From 196d9a5780a54132373f075682e73a69c6f061e6 Mon Sep 17 00:00:00 2001
From: AzraelSec <me@azraelsec.sh>
Date: Sun, 5 Nov 2023 12:13:01 +0100
Subject: [PATCH] wip
---
pkg/commands/oscommands/cmd_obj_builder.go | 3 ++-
pkg/commands/oscommands/os_test.go | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/pkg/commands/oscommands/cmd_obj_builder.go b/pkg/commands/oscommands/cmd_obj_builder.go
index 77fb7e7c..0b8ed55c 100644
--- a/pkg/commands/oscommands/cmd_obj_builder.go
+++ b/pkg/commands/oscommands/cmd_obj_builder.go
@@ -66,7 +66,7 @@ func (self *CmdObjBuilder) CloneWithNewRunner(decorate func(ICmdObjRunner) ICmdO
}
}
-const CHARS_REQUIRING_QUOTES = "\"\\$` "
+const CHARS_REQUIRING_QUOTES = "\"\\$` '"
// If you update this method, be sure to update CHARS_REQUIRING_QUOTES
func (self *CmdObjBuilder) Quote(message string) string {
@@ -76,6 +76,7 @@ func (self *CmdObjBuilder) Quote(message string) string {
message = strings.NewReplacer(
`"`, `"'"'"`,
`\"`, `\\"`,
+ `'`, `\'`,
).Replace(message)
} else {
quote = `"`
diff --git a/pkg/commands/oscommands/os_test.go b/pkg/commands/oscommands/os_test.go
index fbae7685..9f5c84db 100644
--- a/pkg/commands/oscommands/os_test.go
+++ b/pkg/commands/oscommands/os_test.go
@@ -75,7 +75,7 @@ func TestOSCommandQuoteWindows(t *testing.T) {
actual := osCommand.Quote(`hello "test" 'test2'`)
- expected := `\"hello "'"'"test"'"'" 'test2'\"`
+ expected := `\"hello "'"'"test"'"'" \'test2\'\"`
assert.EqualValues(t, expected, actual)
}
--
2.42.0
@AzraelSec unfortunately that didn't solve it, but I'll try to dig there as well.
Btw try out https://github.com/quickemu-project/quickemu for a Windows VM, it basically boils down to two shell commands.
This patch fixes it for me:
diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go
index fc13eedf..815838d9 100644
--- a/pkg/commands/oscommands/os.go
+++ b/pkg/commands/oscommands/os.go
@@ -1,7 +1,6 @@
package oscommands
import (
- "fmt"
"io"
"os"
"os/exec"
@@ -340,6 +339,6 @@ func (c *OSCommand) UpdateWindowTitle() error {
if getWdErr != nil {
return getWdErr
}
- argString := fmt.Sprint("title ", filepath.Base(path), " - Lazygit")
- return c.Cmd.NewShell(argString).Run()
+ args := []string{"cmd", "/c", "title " + filepath.Base(path) + " - Lazygit"}
+ return c.Cmd.New(args).Run()
}
I didn't test this extensively, e.g. what happens when there are other special characters in the string, or double quotes, or whatever.
I don't have time to turn this into a PR, if anybody feels like picking it up from here, feel free!
Describe the bug If my current directory has a
'
in the name, lazygit will crashTo Reproduce Steps to reproduce the behavior:
test ' hello
Expected behavior Lazygit running
Screenshots No screenshot but i have this error:
Version info: Run
lazygit --version
and paste the result herecommit=5e388e21c8ca6aa883dbcbe45c47f6fdd5116815, build date=2023-08-07T14:05:48Z, build source=binaryRelease, version=0.40.2, os=windows, arch=amd64, git version=2.33.0.windows.2
Run
git --version
and paste the result heregit version 2.33.0.windows.2
Additional context This was brought up on #890, and was "fixed" but it apparently still happens
I haven't tried compiling from the latest
master
branch, since I don't know anything about Go.