[ruby/optparse] 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.

https://github.com/ruby/optparse/commit/30571f91d3
This commit is contained in:
Kouhei Yanagita 2025-01-09 11:00:54 +09:00 committed by git
parent f4c16c57aa
commit 3cd3f76679

View File

@ -1058,7 +1058,7 @@ XXX
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