Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

MemCacheStore can't deal with Umlauts and special characters

#6225

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

Reported by zoopzoop · December 26th, 2010 @ 11:35 PM

State: new
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Pan Thomakos
    Pan Thomakos

    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.

    March 5th, 2011 @ 07:37 PM

  2. Matt Jones
    Matt Jones
    • Tag changed from memcachestore to memcachestore, patch
    • Importance changed from to Low

    March 5th, 2011 @ 09:13 PM

  3. Pan Thomakos
    Pan Thomakos

    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.

    March 5th, 2011 @ 10:25 PM

  4. Pan Thomakos
  5. Mike Perham
    Mike Perham

    I had the same issue in Dalli and fixed it in a similar manner:

    https://github.com/mperham/dalli/issues/78

    March 25th, 2011 @ 04:42 PM

  6. Pan Thomakos
    Pan Thomakos

    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.

    March 25th, 2011 @ 04:55 PM