fix(iostreams): treat a blank pager command as no pager

What does this MR do and why?

Setting PAGER to whitespace panics glab:

$ PAGER="   " glab mr list
panic: runtime error: slice bounds out of range [1:0]

StartPager guards against an empty pager command but not a blank one:

if s.pagerCommand == "" || s.pagerCommand == "cat" || !s.IsaTTY {
	return nil
}

pagerArgs, err := shlex.Split(s.pagerCommand)
...
pagerCmd := exec.Command(pagerArgs[0], pagerArgs[1:]...)

shlex.Split(" ") yields an empty slice, so pagerArgs[1:] goes out of range.

A blank value means the same thing as an unset one, so this is handled at the existing guard with strings.TrimSpace rather than by adding a new error path. Returning an error would be worse for the user: every paged command would start failing because of a stray space in an environment variable.

Test coverage

TestStartPager_BlankCommand covers " ", "\t", "\n" and " \t\n ". It asserts no error and that StdOut is untouched, which is what actually distinguishes "no pager was started" from "a pager was wired up".

Reverting only iostreams.go:

--- FAIL: TestStartPager_BlankCommand/"___"
panic: runtime error: slice bounds out of range [1:0]

With the fix, go test ./internal/iostreams/ is green.

Closes #8424 (closed)

Merge request reports

Loading
Loading