fix: handling of EDITOR env var (#10855)
The `ipfs config edit` command did not correctly handle the `EDITOR` environment variable correctly when its value contains flags and arguments, i.e. `EDITOR=emacs -nw`. The command was treating the entire value of `$EDITOR` as the name of the editor command. This has been fixed to parse the value of `$EDITOR` into separate args, respecting shell quoting. Closes #9375
Andrew Gillis committed
Jul 8, 2025 at 09:00 UTC
4195a1da9fffec4451cc10de6b12b4751fc31b56
4 files changed
+20
-5
core/commands/config.go
+12
-5
@@ -9,13 +9,13 @@ import (
9
"os/exec"
10
"strings"
11
12
- "github.com/ipfs/kubo/core/commands/cmdenv"
13
- "github.com/ipfs/kubo/repo"
14
- "github.com/ipfs/kubo/repo/fsrepo"
15
-
12
+ "github.com/anmitsu/go-shlex"
13
"github.com/elgris/jsondiff"
14
cmds "github.com/ipfs/go-ipfs-cmds"
15
config "github.com/ipfs/kubo/config"
16
+ "github.com/ipfs/kubo/core/commands/cmdenv"
17
+ "github.com/ipfs/kubo/repo"
18
+ "github.com/ipfs/kubo/repo/fsrepo"
19
)
20
21
// ConfigUpdateOutput is config profile apply command's output
@@ -512,7 +512,14 @@ func editConfig(filename string) error {
512
return errors.New("ENV variable $EDITOR not set")
513
}
514
515
- cmd := exec.Command(editor, filename)
515
+ editorAndArgs, err := shlex.Split(editor, true)
516
+ if err != nil {
517
+ return fmt.Errorf("cannot parse $EDITOR value: %s", err)
518
+ }
519
+ editor = editorAndArgs[0]
520
+ args := append(editorAndArgs[1:], filename)
521
+
522
+ cmd := exec.Command(editor, args...)
523
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
524
return cmd.Run()
525
}
docs/changelogs/v0.36.md
+5
@@ -18,6 +18,7 @@ This release was brought to you by the [Interplanetary Shipyard](https://ipship
18
- [Overwrite option for files cp command](#overwrite-option-for-files-cp-command)
19
- [Option for filestore command to remove bad blocks](#option-for-filestore-command-to-remove-bad-blocks)
20
- [`ConnMgr.SilencePeriod` configuration setting exposed](#connmgrsilenceperiod-configuration-setting-exposed)
21
+ - [Fix handling of EDITOR env var](#fix-handling-of-editor-env-var)
22
- [📦️ Important dependency updates](#-important-dependency-updates)
23
- [📝 Changelog](#-changelog)
24
- [👨👩👧👦 Contributors](#-contributors)
@@ -79,6 +80,10 @@ The `filestore` command has a new option, `--remove-bad-blocks`, to verify objec
80
81
This connection manager option controls how often connections are swept and potentially terminated. See the [ConnMgr documentation](https://github.com/ipfs/kubo/blob/master/docs/config.md#swarmconnmgrsilenceperiod).
82
83
+#### Fix handling of EDITOR env var
84
+
85
+The `ipfs config edit` command did not correctly handle the `EDITOR` environment variable correctly when its value contains flags and arguments, i.e. `EDITOR=emacs -nw`. The command was treating the entire value of `$EDITOR` as the name of the editor command. This has been fixed to parse the value of `$EDITOR` into separate args, respecting shell quoting.
86
+
87
#### 📦️ Important dependency updates
88
89
- update `go-libp2p` to [v0.42.0](https://github.com/libp2p/go-libp2p/releases/tag/v0.42.0)
go.mod
+1
@@ -5,6 +5,7 @@ go 1.24
5
require (
6
bazil.org/fuse v0.0.0-20200117225306-7b5117fecadc
7
contrib.go.opencensus.io/exporter/prometheus v0.4.2
8
+ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239
9
github.com/blang/semver/v4 v4.0.0
10
github.com/caddyserver/certmagic v0.21.6
11
github.com/cenkalti/backoff/v4 v4.3.0
go.sum
+2
@@ -66,6 +66,7 @@ github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b h1:mimo19zliBX/vS
66
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b/go.mod h1:fvzegU4vN3H1qMT+8wDmzjAcDONcgo2/SZ/TyfdUOFs=
67
github.com/alexbrainman/goissue34681 v0.0.0-20191006012335-3fc7a47baff5 h1:iW0a5ljuFxkLGPNem5Ui+KBjFJzKg4Fv2fnxe4dvzpM=
68
github.com/alexbrainman/goissue34681 v0.0.0-20191006012335-3fc7a47baff5/go.mod h1:Y2QMoi1vgtOIfc+6DhrMOGkLoGzqSV2rKp4Sm+opsyA=
69
+github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
70
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
71
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
72
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
@@ -180,6 +181,7 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
181
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
182
github.com/filecoin-project/go-clock v0.1.0 h1:SFbYIM75M8NnFm1yMHhN9Ahy3W5bEZV9gd6MPfXbKVU=
183
github.com/filecoin-project/go-clock v0.1.0/go.mod h1:4uB/O4PvOjlx1VCMdZ9MyDZXRm//gkj1ELEbxfI1AZs=
184
+github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
185
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
186
github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg=
187
github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=