Skip FZF_CURRENT_ITEM export when item contains NUL

- exec(2) rejects env entries containing NUL, breaking preview and
  other child commands when the input has NUL bytes
- skip the export and document the limitation

Fix #2395
This commit is contained in:
Junegunn Choi
2026-05-25 14:06:50 +09:00
parent 3953d1c649
commit 4b23aa45a8
2 changed files with 8 additions and 1 deletions
+4
View File
@@ -1531,6 +1531,10 @@ fzf exports the following environment variables to its child processes.
.br
.BR FZF_RAW " Only in raw mode. 1 if the current item matches, 0 otherwise"
.PP
.B FZF_CURRENT_ITEM
is omitted when the item contains a NUL byte, because exec(2) cannot pass it.
.SH EXTENDED SEARCH MODE
Unless specified otherwise, fzf will start in "extended\-search mode". In this
+4 -1
View File
@@ -1439,7 +1439,10 @@ func (t *Terminal) environImpl(forPreview bool) []string {
env = append(env, fmt.Sprintf("FZF_COLUMNS=%d", t.areaColumns))
env = append(env, fmt.Sprintf("FZF_POS=%d", min(t.merger.Length(), t.cy+1)))
if item := t.currentItem(); item != nil {
env = append(env, "FZF_CURRENT_ITEM="+item.AsString(t.ansi))
// Skip if the value contains a NUL byte; exec(2) would reject the env.
if s := item.AsString(t.ansi); !strings.ContainsRune(s, 0) {
env = append(env, "FZF_CURRENT_ITEM="+s)
}
}
env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_LINE=%d", t.clickHeaderLine))
env = append(env, fmt.Sprintf("FZF_CLICK_HEADER_COLUMN=%d", t.clickHeaderColumn))