Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash.from_xml error #3512

Closed
hathawad opened this issue Dec 2, 2015 · 2 comments
Closed

Hash.from_xml error #3512

hathawad opened this issue Dec 2, 2015 · 2 comments
Labels
Milestone

Comments

@hathawad
Copy link

hathawad commented Dec 2, 2015

Using rails 3.2 active support method Hash.from_xml produces an error when passed a File object.

Works in JRuby 1.7.22, broken in 9.0.4.0

Recreate (w/ Rails active support):

simple_hash = { :test => {:a => "b", :c => "d"} }.to_xml
File.open("simple_hash.xml", "w"){|f| f << simple_hash}
xml_file = File.open("simple_hash.xml")
Hash.from_xml(xml_file)['hash'] # Throws Exception 

Error

IOError: byte oriented read for character buffered IO
        from nokogiri/XmlDocument.java:327:in `read_io'
        from C:/jruby-9.0.4.0/lib/ruby/gems/shared/gems/nokogiri-1.5.5-java/lib/nokogiri/xml/document.rb:50:in `parse'
        from C:/jruby-9.0.4.0/lib/ruby/gems/shared/gems/nokogiri-1.5.5-java/lib/nokogiri/xml.rb:33:in `XML'
        from C:/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activesupport-3.2.20/lib/active_support/xml_mini/nokogiri.rb:28:in `parse'
        from C:98:in `parse'
        from C:/jruby-9.0.4.0/lib/ruby/gems/shared/gems/activesupport-3.2.20/lib/active_support/core_ext/hash/conversions.rb:98:in `from_xml'
        from (irb):20:in `<eval>'
        from org/jruby/RubyKernel.java:978:in `eval'
        from org/jruby/RubyKernel.java:1291:in `loop'
        from org/jruby/RubyKernel.java:1098:in `catch'
        from org/jruby/RubyKernel.java:1098:in `catch'
        from C:/jruby-9.0.4.0/lib/ruby/gems/shared/gems/railties-3.2.20/lib/rails/commands/console.rb:47:in `start'
        from C:/jruby-9.0.4.0/lib/ruby/gems/shared/gems/railties-3.2.20/lib/rails/commands/console.rb:8:in `start'
        from C:/jruby-9.0.4.0/lib/ruby/gems/shared/gems/railties-3.2.20/lib/rails/commands.rb:41:in `<top>'
        from org/jruby/RubyKernel.java:939:in `require'
        from script/rails:6:in `<top>'

Environment

jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa Java HotSpot(TM) 64-Bit Server VM 25.65-b01 on 1.8.0_65-b17 +jit [Windows Server 2008 R2-amd64]
@kares
Copy link
Member

kares commented Apr 9, 2016

seems to work with 9.0.5 and Rails 3.2.22 (installed same version of nokogiri -v 1.5.5) :

jruby-9.0.5.0 :001 > require 'active_support/all'
 => true 
jruby-9.0.5.0 :002 > simple_hash = { :test => {:a => "b", :c => "d"} }.to_xml
 => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n  <test>\n    <a>b</a>\n    <c>d</c>\n  </test>\n</hash>\n" 
jruby-9.0.5.0 :003 > File.open("simple_hash.xml", "w"){|f| f << simple_hash}
 => #<File:simple_hash.xml (closed)> 
jruby-9.0.5.0 :004 > xml_file = File.open("simple_hash.xml")
 => #<File:simple_hash.xml> 
jruby-9.0.5.0 :005 > Hash.from_xml(xml_file)['hash'] # Throws Exception 
 => {"test"=>{"a"=>"b", "c"=>"d"}} 
jruby-9.0.5.0 :006 > 
jruby-9.0.5.0 :007 >   puts ActiveSupport::VERSION::STRING
3.2.22.2

@kares kares closed this as completed Apr 9, 2016
@kares kares added the Rails label Apr 9, 2016
@kares kares added this to the JRuby 9.0.5.0 milestone Apr 9, 2016
@hathawad
Copy link
Author

it may be worth mentioning the my example code above still fails in 9.1.2.0, however if the line

xml_file = File.open("simple_hash.xml")

is changed to

xml_file = File.open("simple_hash.xml","rb")

everything works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants