Jruby --1.9 behaves different from MRI1.9.2 using yaml

I’m getting crazy with this problem: strings loaded through yaml appear
different in MRI 1.9.2 and jruby with --1.9.

Have a look:

$ cat data_row.rb
class DataRow
def initialize(hash)
hash.each do |key, value|
# be sure values are not null
if is_not_null(value)
instance_variable_set("@#{key}", “#{value}”)
end
end
end

def is_not_null(v)

puts “#{v} = <#{v.strip}>” if v

v and !(v.strip.eql?(""))

end
end

$ cat test_data_row.rb
require ‘test/unit’
require ‘data_row’
require ‘yaml’

class TestDataRow < Test::Unit::TestCase
def test_empty_string

yamldata =<<YAML

empty:
broken: " "
not_empty: " ()"
YAML
yaml = YAML.load yamldata
d = DataRow.new(yaml)

assert_nil d.instance_eval {@broken}

end
end

test passes with jruby1.6.0, with plain ruby1.9.2, but fails with
jruby1.6.0 --1.9

It is definitely a yaml problem: as soon as I substitute the hash loaded
from yaml with a plain hash everything works.

Stanger still, if you uncomment debug line:
puts “#{v} = <#{v.strip}>” if v
and run under jruby1.6.0 --1.9 this error follows:

ArgumentError: negative string size (or size too big)
/homel/francesco/sviluppo/ruby/scratchbox/bug/data_row.rb:12:in
is_not_null' /homel/francesco/sviluppo/ruby/scratchbox/bug/data_row.rb:5:ininitialize’
org/jruby/RubyHash.java:1172:in each' /homel/francesco/sviluppo/ruby/scratchbox/bug/data_row.rb:3:ininitialize’
test_data_row.rb:17:in test_empty_string' org/jruby/RubyBasicObject.java:1665:insend

Pardon if I missed something, but I’m really upset and surprised by this
behaviour.

Thank you to all for this great jruby,

Francesco

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs