2

我有一个 Rails 3.2.8 应用程序。它在 Ruby 1.9.3 和 JRuby 1.6.7.2 下以 1.9 兼容模式运行。在 JRuby 下插入数据库有时会崩溃。

这是我的 en.yml 文件:

en:
  moo: "you’re"
  meep: "you"
  bar: "\"Booón\""
  baz: "Booón"

假设我有一个 Message 对象,它有两个属性,发送者和主题。以下是发件人和主题的几种可能组合

msg = Message.new(subject: "sblah", sender: I18n.t("bar"))
msg.save

msg = Message.new(subject: "sblah", sender: I18n.t("baz"))
msg.save

msg = Message.new(subject: I18n.t("moo"), sender: I18n.t("baz"))
msg.save

msg = Message.new(subject: I18n.t("moo"), sender: "temp")
msg.save

msg = Message.new(subject: I18n.t("meep"), sender: I18n.t("bar"))
msg.save

# Mystery crash
msg = Message.new(subject: I18n.t("moo"), sender: I18n.t("bar"))
msg.save

在 JRuby 1.6.7.2(兼容 1.9)下运行时,最后一个会导致崩溃。MRI 1.9.3p194不会发生崩溃。

似乎需要结合(重音字符和引号)和(卷曲撇号)来触发崩溃。拿走这些东西中的任何一件。没有崩溃。

Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
    from org/jruby/RubyString.java:2926:in `gsub'
    from /Users/paul/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-1.2.2/lib/arjdbc/mysql/adapter.rb:485:in `exec_insert'
    from /Users/paul/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/database_statements.rb:90:in `insert'
    from /Users/paul/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/query_cache.rb:19:in `insert'
    from /Users/paul/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/relation.rb:66:in `insert'
    from /Users/paul/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/persistence.rb:366:in `create'
    from /Users/paul/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/timestamp.rb:57:in `create'
    from /Users/paul/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activerecord-3.2.8/lib/active_record/callbacks.rb:268:in `create'
    from /Users/paul/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:406:in `_run__142677804__create__486269792__callbacks'
    from org/jruby/RubyBasicObject.java:1698:in `__send__'
    from org/jruby/RubyKernel.java:2097:in `send'
    from /Users/paul/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
    from /Users/paul/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:390:in `_run_create_callbacks'
    from org/jruby/RubyBasicObject.java:1698:in `__send__'
    from org/jruby/RubyKernel.java:2097:in `send'
    from /Users/paul/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
... 17 levels...

这是崩溃的代码:

480       def exec_insert(sql, name, binds)
481         binds = binds.dup
482 
483         # Pretend to support bind parameters
484         unless binds.empty?
485           sql = sql.gsub('?') { quote(*binds.shift.reverse) }                                       
486         end
487         execute sql, name
488       end
4

0 回答 0