开发者

Ruby 1.9 -Ku, mem_cache_store and invalid multibyte escape error

开发者 https://www.devze.com 2023-01-23 03:29 出处:网络
Originally this bug was posted here: https://rails.lighthouseapp.com/projects/8994/tickets/5713-ruby-19-ku-incompatible-with-mem_cache_store

Originally this bug was posted here: https://rails.lighthouseapp.com/projects/8994/tickets/5713-ruby-19-ku-incompatible-with-mem_cache_store And now, as we've run into the same issue, I'll copy here a question from that issue, hoping someone have an answer already: When Ruby 1.9 is started in unicode mode (-Ku), mem_cache_store.rb fails to parse:

/usr/local/ruby19/bin/ruby -Ku /usr/local/ruby-1.9.2-p0/lib/ruby/gems/1.9.1/gems/
  activesupport-3.0.0/lib/active_support/cache/mem_cache_store.rb
/usr/local/ruby-1.9.2-p0/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/
  cache/mem_cache_store.rb:32: invalid multibyte escape: /[\x00-\x20%\x7F-\xFF]/

Our case is practically identical: when you set config.action_controller.cache_store to :mem_cache_store, and try to run tests, console, or server, you recieve this in return:

/Users/%username%/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.1/lib/active_support/
  cache/mem_cache_store.rb:32: invalid multibyte escape: /[\x00-\x20%\x7F-\xFF]/

An开发者_StackOverflowy ideas how this can be avoided?..


Ruby 1.9 in unicode mode will attempt to interpret the regular expression as unicode. To avoid this you need to pass the regular expression option "n" for "no encoding":

ESCAPE_KEY_CHARS = /[\x00-\x20%\x7F-\xFF]/n

Now we have our raw 8-bit encoding (the only thing Ruby 1.8 speaks) as intended:

ruby-1.9.2-p136 :001 > ESCAPE_KEY_CHARS = /[\x00-\x20%\x7F-\xFF]/n.encoding
=> # <Encoding:ASCII-8BIT>

Hopefully the Rails teams fixes this, for now you have to edit the file.

0

精彩评论

暂无评论...
验证码 换一张
取 消