【问题标题】:Ruby 1.9 -Ku, mem_cache_store and invalid multibyte escape errorRuby 1.9 -Ku、mem_cache_store 和无效的多字节转义错误
【发布时间】:2011-05-03 09:53:15
【问题描述】:

这个错误最初是在这里发布的:https://rails.lighthouseapp.com/projects/8994/tickets/5713-ruby-19-ku-incompatible-with-mem_cache_store 现在,由于我们遇到了同样的问题,我将在此处复制该问题中的一个问题,希望有人已经有了答案: Ruby 1.9 以 unicode 模式(-Ku)启动时,mem_cache_store.rb 解析失败:

/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]/

我们的情况实际上是相同的:当您将 config.action_controller.cache_store 设置为 :mem_cache_store,并尝试运行测试、控制台或服务器时,您会收到以下信息:

/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]/

有什么办法可以避免这种情况吗?..

【问题讨论】:

    标签: ruby caching ruby-on-rails-3 memcached ruby-1.9


    【解决方案1】:

    Unicode 模式下的 Ruby 1.9 将尝试将正则表达式解释为 unicode。为避免这种情况,您需要为“无编码”传递正则表达式选项“n”:

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

    现在我们有了原始的 8 位编码(Ruby 1.8 唯一的语言):

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

    希望 Rails 团队解决此问题,现在您必须编辑文件。

    【讨论】:

      猜你喜欢
      • 2011-07-25
      • 2011-04-10
      • 2010-12-16
      • 1970-01-01
      • 1970-01-01
      • 2011-02-28
      • 1970-01-01
      • 2012-09-22
      • 1970-01-01
      相关资源
      最近更新 更多