Skip to content

Commit d8086e6

Browse files
committed
Allow WEBrick::HTTPServlet::CGIHandler :CGIInterpreter option to be array
This way you don't need to escape each entry. Implements Ruby Feature 15170.
1 parent 8cff7f3 commit d8086e6

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/webrick/httpservlet/cgihandler.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module HTTPServlet
2828
class CGIHandler < AbstractServlet
2929
Ruby = RbConfig.ruby # :nodoc:
3030
CGIRunner = "\"#{Ruby}\" \"#{WEBrick::Config::LIBDIR}/httpservlet/cgi_runner.rb\"" # :nodoc:
31+
CGIRunnerArray = [Ruby, "#{WEBrick::Config::LIBDIR}/httpservlet/cgi_runner.rb".freeze].freeze # :nodoc:
3132

3233
##
3334
# Creates a new CGI script servlet for the script at +name+
@@ -36,7 +37,12 @@ def initialize(server, name)
3637
super(server, name)
3738
@script_filename = name
3839
@tempdir = server[:TempDir]
39-
@cgicmd = "#{CGIRunner} #{server[:CGIInterpreter]}"
40+
interpreter = server[:CGIInterpreter]
41+
if interpreter.is_a?(Array)
42+
@cgicmd = CGIRunnerArray + interpreter
43+
else
44+
@cgicmd = "#{CGIRunner} #{interpreter}"
45+
end
4046
end
4147

4248
# :stopdoc:

test/webrick/test_filehandler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def test_script_disclosure
289289
return if File.executable?(__FILE__) # skip on strange file system
290290

291291
config = {
292-
:CGIInterpreter => TestWEBrick::RubyBin,
292+
:CGIInterpreter => TestWEBrick::RubyBinArray,
293293
:DocumentRoot => File.dirname(__FILE__),
294294
:CGIPathEnv => ENV['PATH'],
295295
:RequestCallback => Proc.new{|req, res|

test/webrick/utils.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class WEBrick::HTTPServlet::CGIHandler
1919
Ruby = EnvUtil.rubybin
2020
remove_const :CGIRunner
2121
CGIRunner = "\"#{Ruby}\" \"#{WEBrick::Config::LIBDIR}/httpservlet/cgi_runner.rb\"" # :nodoc:
22+
remove_const :CGIRunnerArray
23+
CGIRunnerArray = [Ruby, "#{WEBrick::Config::LIBDIR}/httpservlet/cgi_runner.rb"] # :nodoc:
2224
end
2325

2426
RubyBin = "\"#{EnvUtil.rubybin}\""
@@ -27,6 +29,12 @@ class WEBrick::HTTPServlet::CGIHandler
2729
RubyBin << " \"-I#{File.dirname(EnvUtil.rubybin)}/.ext/common\""
2830
RubyBin << " \"-I#{File.dirname(EnvUtil.rubybin)}/.ext/#{RUBY_PLATFORM}\""
2931

32+
RubyBinArray = [EnvUtil.rubybin]
33+
RubyBinArray << "--disable-gems"
34+
RubyBinArray << "-I" << "#{File.expand_path("../..", File.dirname(__FILE__))}/lib"
35+
RubyBinArray << "-I" << "#{File.dirname(EnvUtil.rubybin)}/.ext/common"
36+
RubyBinArray << "-I" << "#{File.dirname(EnvUtil.rubybin)}/.ext/#{RUBY_PLATFORM}"
37+
3038
require "test/unit" unless defined?(Test::Unit)
3139
include Test::Unit::Assertions
3240
extend Test::Unit::Assertions

0 commit comments

Comments
 (0)