[Rubygems-developers] [ rubygems-Patches-28644 ] File.read in source_index.rb uses Ruby 1.9 syntax, breaks in 1.8

noreply at rubyforge.org noreply at rubyforge.org
Tue Oct 12 15:08:22 EDT 2010


Patches item #28644, was opened at 2010-10-12 15:08
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=577&aid=28644&group_id=126

Category: other
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Matt Savona (loopforever)
Assigned to: Nobody (None)
Summary: File.read in source_index.rb uses Ruby 1.9 syntax, breaks in 1.8

Initial Comment:
One of our users noted the following issue after an upgrade to RubyGems 1.3.7:

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails 2.1.0 application starting on http://0.0.0.0:9296
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:9296
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
Exiting
/usr/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:89:in `read': can't convert Hash into Integer (TypeError)
        from /usr/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:89:in `load_specification'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:153:in `load_gems_in'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:152:in `each'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:152:in `load_gems_in'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:149:in `reverse_each'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:149:in `load_gems_in'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:345:in `refresh!'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:78:in `from_gems_in'
         ... 23 levels...
        from /usr/lib64/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from script/server:3


The reason for this is because source_index.rb:89 uses the following syntax for File.read when the Encoding constant is defined:

 88       spec_code = if defined? Encoding then
 89                     File.read file_name, :encoding => 'UTF-8'
 90                   else
 91                     File.read file_name
 92                   end.untaint

This syntax appears to only be valid in Ruby 1.9. Our environment is:

ruby 1.8.6 (2008-08-11 patchlevel 287) [x86_64-linux]

I made a very small patch to source_index.rb, which is attached. It will only utilize the Ruby 1.9 File.read syntax if the Encoding constant is defined and RUBY_VERSION.to_f >= 1.9.

Please apply upstream if you find this to be an appropriate workaround. Thank you!

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=577&aid=28644&group_id=126


More information about the Rubygems-developers mailing list