2010-11-01 51 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團隊修復此問題,因爲現在您必須編輯該文件。

相關問題