From 76181156ba1fd6ae8eb4b17dc933e7d0b53bcad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 14 Sep 2020 16:49:30 +0200 Subject: [PATCH] Prevent endless recursive pager Unset PAGER environment variable when executing the command referenced in PAGER in case that command also has support for PAGER and would end up executing itself indefinitely. --- pkg/iostreams/iostreams.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/iostreams/iostreams.go b/pkg/iostreams/iostreams.go index 9de8ab8d7..e3694dfe5 100644 --- a/pkg/iostreams/iostreams.go +++ b/pkg/iostreams/iostreams.go @@ -103,6 +103,11 @@ func (s *IOStreams) StartPager() error { } pagerEnv := os.Environ() + for i := len(pagerEnv) - 1; i >= 0; i-- { + if strings.HasPrefix(pagerEnv[i], "PAGER=") { + pagerEnv = append(pagerEnv[0:i], pagerEnv[i+1:]...) + } + } if _, ok := os.LookupEnv("LESS"); !ok { pagerEnv = append(pagerEnv, "LESS=FRX") }