Skip to content

Commit 4195a1d

Browse files
authored
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
1 parent b95845e commit 4195a1d

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

core/commands/config.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
"os/exec"
1010
"strings"
1111

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"
1613
"github.com/elgris/jsondiff"
1714
cmds "github.com/ipfs/go-ipfs-cmds"
1815
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"
1919
)
2020

2121
// ConfigUpdateOutput is config profile apply command's output
@@ -512,7 +512,14 @@ func editConfig(filename string) error {
512512
return errors.New("ENV variable $EDITOR not set")
513513
}
514514

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...)
516523
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
517524
return cmd.Run()
518525
}

docs/changelogs/v0.36.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This release was brought to you by the [Interplanetary Shipyard](https://ipship
1818
- [Overwrite option for files cp command](#overwrite-option-for-files-cp-command)
1919
- [Option for filestore command to remove bad blocks](#option-for-filestore-command-to-remove-bad-blocks)
2020
- [`ConnMgr.SilencePeriod` configuration setting exposed](#connmgrsilenceperiod-configuration-setting-exposed)
21+
- [Fix handling of EDITOR env var](#fix-handling-of-editor-env-var)
2122
- [📦️ Important dependency updates](#-important-dependency-updates)
2223
- [📝 Changelog](#-changelog)
2324
- [👨‍👩‍👧‍👦 Contributors](#-contributors)
@@ -79,6 +80,10 @@ The `filestore` command has a new option, `--remove-bad-blocks`, to verify objec
7980

8081
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).
8182

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+
8287
#### 📦️ Important dependency updates
8388

8489
- update `go-libp2p` to [v0.42.0](https://github.com/libp2p/go-libp2p/releases/tag/v0.42.0)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.24
55
require (
66
bazil.org/fuse v0.0.0-20200117225306-7b5117fecadc
77
contrib.go.opencensus.io/exporter/prometheus v0.4.2
8+
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239
89
github.com/blang/semver/v4 v4.0.0
910
github.com/caddyserver/certmagic v0.21.6
1011
github.com/cenkalti/backoff/v4 v4.3.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b h1:mimo19zliBX/vS
6666
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b/go.mod h1:fvzegU4vN3H1qMT+8wDmzjAcDONcgo2/SZ/TyfdUOFs=
6767
github.com/alexbrainman/goissue34681 v0.0.0-20191006012335-3fc7a47baff5 h1:iW0a5ljuFxkLGPNem5Ui+KBjFJzKg4Fv2fnxe4dvzpM=
6868
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=
6970
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
7071
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
7172
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
@@ -180,6 +181,7 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
180181
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
181182
github.com/filecoin-project/go-clock v0.1.0 h1:SFbYIM75M8NnFm1yMHhN9Ahy3W5bEZV9gd6MPfXbKVU=
182183
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=
183185
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
184186
github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg=
185187
github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=

0 commit comments

Comments
 (0)