Project

General

Profile

Bug #1314

CGI doesn૑t properly handle empty arguments

Added by Smar (Samu Voutilainen) over 10 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
ruby -v:
ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]

Description

=begin
In case you are trying to initialise with CGI.new, on non-interactive ૓terminal૓, Ruby fails with:

/usr/lib64/ruby/1.8/cgi.rb:1092:in readlines': Invalid argument (Errno::EINVAL)
from /usr/lib64/ruby/1.8/cgi.rb:1092:in
read_from_cmdline'

from /usr/lib64/ruby/1.8/cgi.rb:1129:in initialize_query'
from /usr/lib64/ruby/1.8/cgi.rb:2281:in
initialize'

I fixed it by modifying read_from_cmdline a bit:

 # offline mode. read name=value pairs on standard input.
 def read_from_cmdline
     require "shellwords"

     string = unless ARGV.empty?
         ARGV.join(' ')
     else
         if STDIN.tty?
             STDERR.print(
                 %|(offline mode: enter name=value pairs on standard input)\n|
             )
         end
         array = nil
         begin
             readlines
         rescue
         end
         if not array.nil?
             array.join(' ').gsub(/\n/n, '')
         else
             ""
         end
     end.gsub(/\\=/n, '%3D').gsub(/\\&/n, '%26')

     words = Shellwords.shellwords(string)

     if words.find{|x| /=/n.match(x) }
         words.join('&')
     else
         words.join('+')
     end
 end

Sorry that it isn૑t patch, I just edited cgi.rb found from my system...
=end

Associated revisions

Revision 5f671527
Added by hsbt (Hiroshi SHIBATA) almost 4 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 52666
Added by hsbt (Hiroshi SHIBATA) almost 4 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

Revision 52666
Added by hsbt (Hiroshi SHIBATA) almost 4 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

Revision 52666
Added by hsbt (Hiroshi SHIBATA) almost 4 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

Revision 52666
Added by hsbt (Hiroshi SHIBATA) almost 4 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

Revision 52666
Added by hsbt (Hiroshi SHIBATA) almost 4 years ago

  • lib/rubygems: Update to RubyGems 2.5.0+ HEAD(c6b4946). this version includes #1114, #1314, #1322, #1375, #1383, #1387
  • test/rubygems: ditto.

History

#1

Updated by naruse (Yui NARUSE) almost 10 years ago

  • Assignee set to xibbar (Takeyuki FUJIOKA)

=begin

=end

#2

Updated by xibbar (Takeyuki FUJIOKA) almost 10 years ago

  • Status changed from Open to Assigned
  • Assignee changed from xibbar (Takeyuki FUJIOKA) to knu (Akinori MUSHA)

=begin
I commited for trunk of this update.
Please choice backport or reject for ruby-1.8 branch
and change status.
May I commit this update ?
=end

#3

Updated by knu (Akinori MUSHA) almost 10 years ago

  • Assignee changed from knu (Akinori MUSHA) to xibbar (Takeyuki FUJIOKA)

=begin
Seems to me the change made on trunk is wrong because the result of "readlines" is never assigned to "array".

I think you can replace the following lines:

array = nil
begin
...
end

with just one line:

array = readlines rescue nil

You can backport a fix to ruby_1_8 after the problem is properly fixed on trunk.
Thanks!
=end

#4

Updated by xibbar (Takeyuki FUJIOKA) almost 10 years ago

  • Status changed from Assigned to Closed

=begin

=end

Also available in: Atom PDF