2010-11-01 53 views
1

本来这个bug发布在这里: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无法解析:Ruby 1.9 -Ku,mem_cache_store和无效的多字节转义错误

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

任何想法,这可怎么避免?..

回答

2

红宝石1.9 Unicode模式将尝试解释的正则表达式为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团队修复此问题,因为现在您必须编辑该文件。

相关问题