From 969b99af100eb995316af234deb3840cb0dcd205 Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Mon, 23 Jan 2012 09:33:46 -0800 Subject: [PATCH] .dup key before forcing encoding, GH-162 This matches what AS 3.2 does already. --- History.md | 3 ++- lib/active_support/cache/dalli_store.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index ca2cc192..2377f5be 100644 --- a/History.md +++ b/History.md @@ -4,7 +4,8 @@ Dalli Changelog HEAD ======= -- Fix double namespacing with Rails and dalli\_store. +- Fix encoding issue with keys [#162] +- Fix double namespacing with Rails and dalli\_store. [#160] 1.1.4 ======= diff --git a/lib/active_support/cache/dalli_store.rb b/lib/active_support/cache/dalli_store.rb index caab841d..c339b84d 100644 --- a/lib/active_support/cache/dalli_store.rb +++ b/lib/active_support/cache/dalli_store.rb @@ -149,8 +149,8 @@ def delete_entry(key, options) # :nodoc: private def escape_key(key) - key = key.to_s - key = key.force_encoding('ASCII-8BIT') if key.respond_to? :force_encoding + key = key.to_s.dup + key = key.force_encoding('BINARY') if key.respond_to? :force_encoding key = key.gsub(ESCAPE_KEY_CHARS){|match| "%#{match.getbyte(0).to_s(16).upcase}"} key = "#{key[0, 213]}:md5:#{Digest::MD5.hexdigest(key)}" if key.size > 250 key