From 167a7c1d9320f5c530283a0e9b4aaf74beb5026c Mon Sep 17 00:00:00 2001 From: Kouhei Yanagita Date: Thu, 9 Jan 2025 11:00:54 +0900 Subject: [PATCH] Fix LESS environment variable setup in OptionParser#help_exit If the original value of LESS ends with an option starting with "--", simply appending "Fe" would result in an invalid option string. --- lib/optparse.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/optparse.rb b/lib/optparse.rb index 27e0843..d6863e2 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1053,7 +1053,7 @@ def compsys(to, name = File.basename($0)) # :nodoc: def help_exit if STDOUT.tty? && (pager = ENV.values_at(*%w[RUBY_PAGER PAGER]).find {|e| e && !e.empty?}) less = ENV["LESS"] - args = [{"LESS" => "#{!less || less.empty? ? '-' : less}Fe"}, pager, "w"] + args = [{"LESS" => "#{less} -Fe"}, pager, "w"] print = proc do |f| f.puts help rescue Errno::EPIPE