Conversation
$PAGER is written as a command line by the tools this CLI is used beside (git, gh, man), so PAGER="less -R" is a common configuration. Both pager implementations resolved the whole value as one executable name, so a command that paged its output failed with `exec: "less -R": executable file not found in $PATH` instead of showing the output. pagerCommand() now splits the value into argv for both the pipe pager and the Unix socket-pair pager. Splitting is argv-only, never through a shell, and when the first word does not resolve the whole value is kept so an executable path containing spaces keeps working.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$PAGERis a command line in practice, but both pager implementations inpkg/cmd/cmdutil*.goresolve the whole value as a single executable name. With the very commonPAGER="less -R", any... listcommand whose output is longer than the terminal fails instead of paging.Problem
streamToPagerWithPipeand the UnixopenSocketPairPagereach did:git,ghandmanall documentPAGERasprogram [args...], and those tools are what most users set it beside, soPAGER="less -R"is the configuration this CLI meets in the wild. Both call sites then fail with:streamOutputhas one production caller,ShowJSONIterator(pkg/cmd/cmdutil.go:575), which 68 generated list command sites return through, so the failure is not confined to one command.streamOutputOSSpecificdoes fall back tostreamToPagerWithPipewhen the socket pager fails, but the fallback resolvesPAGERthe same way, so both paths end in the same error.Fix
One
pagerCommand()helper, used by both paths:lesswhen it is empty;strings.Fieldsand returns argv when the first word resolves viaexec.LookPath;The socket pager now passes that argv to
syscall.ForkExec, the pipe pager toexec.Command.No shell is involved. The value is split into argv words only; nothing is ever passed to
sh -c, sodocs/architecture/security-model.md:88-91(a local operator already controlsPAGER) is unaffected in either direction: this neither adds an execution capability nor relies on one.Tests
pkg/cmd/cmdutil_pager_unix_test.go(new,//go:build !windowslike the existingcmdutil_output_errors_unix_test.go):TestPagerCommand— 8 cases: unset, blank, bare program, bare program with surrounding whitespace, program plus two arguments, trimmed value with an argument, a path containing spaces, and an unresolvable first word.TestStreamToPagerPassesPagerArguments— drives both pager implementations through the samepathsmap already used byTestStreamOutputErrorOrigins, with a#!/bin/shfixture that records$1and echoes stdin.PAGER="<fixture> --no-init", and the test asserts the fixture received--no-initand the streamed bytes. The socket subtest assertsw.Name() == "parent-socket"so it cannot silently be covered by the pipe path.Red on the base commit
0169bff(test file copied into a scratch worktree of0169bff):Green on this branch, both subtests.
Validation
cwd
/Users/fei/Desktop/开源/.runtime/2026-09-20/oa/src, base0169bff, go1.25.0 darwin/arm64, network proxies unset,-count=1:go test ./pkg/cmd -run 'TestPagerCommand|TestStreamToPagerPassesPagerArguments' -vgo test ./pkg/cmd -race -run 'TestPagerCommand|TestStreamToPagerPassesPagerArguments|TestStreamOutput|TestShowJSON'go test ./internal/...go test ./pkg/cmdnew failures on branch: [])./scripts/lintgo vet ./...gofmt -lon the three filesGOOS=windows GOARCH=amd64 go build ./...andgo test -c ./pkg/cmdGOOS=linux GOARCH=amd64 go test -c ./pkg/cmdgo mod verify/go mod tidy -diffNot run, and why:
./scripts/test(fullgo test ./...) needs the reviewed Steady mock server on127.0.0.1:4010, which downloads a pinned Deno and fetches the pinned fork. The 284pkg/cmdfailures are all the same precondition error,Mock server is not running on localhost:4010, plus one pre-existing failure I confirmed reproduces unchanged on0169bff:TestFilesCreateCLICancelClosesStalledFIFO→cancellation must close the owned FIFO reader. CI covers the mock-server suite.streamOutputonly reaches a pager whenstdoutis a terminal, so undergo testit short-circuits tostreamToStdout; the new tests therefore callstreamToPagerWithPipe/streamOutputOSSpecificdirectly, which is how the existingcmdutil_output_errors_unix_test.gotests reach them too.Both touched files are wholly handwritten (no
Code generatedheader), so nothing in the generated baseline changes; the Castiron custom-code report will post its own view of the diff.AI-assisted: an AI coding agent produced this change under the account owner's standing instruction for this repo, ran every command above and read its output. No human reviewed the diff before it was opened.