This project is archived and is in readonly mode.
MemCacheStore can't deal with Umlauts and special characters
Reported by zoopzoop | December 26th, 2010 @ 11:35 PM
I get the following exception
Encoding::CompatibilityError: incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)
Backtrace: https://gist.github.com/755724
Setup:
# routes.rb
MyApp::Application.routes.draw do
get ':id' => 'events#show'
end
# events_controller.rb
class EventsController < ApplicationController
caches_action :show
def show
@event = Event.find(params[:id])
end
end
Start Memcached and the Rails server and go to
localhost:3000/á (or è or ü...)
Using Memcached v1.4.5
Comments and changes to this ticket
-
Pan Thomakos March 5th, 2011 @ 07:37 PM
I ran into this same bug with UTF-8 special characters.
The issue is in the ActiveSupport::Cache::MemCacheStore#escape_key function where the key is checked against an ASCII-8BIT regular expression for special characters. I've created a patch to solve this issue by forcing the encoding to comply with the regular expression's encoding in Ruby 1.9. The tests I added also check that any strings formatted any in any other encoding also work. I checked that tests pass for Ruby 1.8.7 and Ruby 1.9.2.
Please try the patch and let me know if everything works.
-
Matt Jones March 5th, 2011 @ 09:13 PM
- Tag changed from memcachestore to memcachestore, patch
- Importance changed from to Low
-
Pan Thomakos March 5th, 2011 @ 10:25 PM
I've update the patch.
After making the original change, I realized that the escape_key function forces the initial string into a new encoding. This means that the escape_key function changes the original encoding of the argument, which can cause problems further down the line in an application.
To fix this I have added another test that checks if the encoding of the original string changes.
Please use this updated patch that dups the argument to avoid this encoding change issue.
-
Mike Perham March 25th, 2011 @ 04:42 PM
I had the same issue in Dalli and fixed it in a similar manner:
-
Pan Thomakos March 25th, 2011 @ 04:55 PM
That's very similar to what I do, but I use the encoding of the ESCAPE_KEY_CHARS, in case it ever changes. If you get a chance, please take a look at the patch or pull request and leave your comments if it works.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>