aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-04-28 09:47:07 +0200
committerJosé Valim <jose.valim@gmail.com>2011-04-28 09:47:07 +0200
commitbb44cd727ff4df0c6baac52ec008289626b874e9 (patch)
treeed53bf1ddc0b272f4bb1133d03aa5b27431b0ac2 /activesupport/lib
parent182d00897a55d01e46087f8ff2646ae86b9ed365 (diff)
downloadrails-bb44cd727ff4df0c6baac52ec008289626b874e9.tar.gz
rails-bb44cd727ff4df0c6baac52ec008289626b874e9.tar.bz2
rails-bb44cd727ff4df0c6baac52ec008289626b874e9.zip
Tidy up previous commit.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index a4b20719cd..7ef1497ac2 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -4,7 +4,9 @@ rescue LoadError => e
$stderr.puts "You don't have memcache-client installed in your application. Please add it to your Gemfile and run bundle install"
raise e
end
+
require 'digest/md5'
+require 'active_support/core_ext/string/encoding'
module ActiveSupport
module Cache
@@ -157,11 +159,14 @@ module ActiveSupport
end
private
+
+ # Memcache keys are binaries. So we need to force their encoding to binary
+ # before applying the regular expression to ensure we are escaping all
+ # characters properly.
def escape_key(key)
- # Fix for EncodedKeyCacheBehavior failing tests in caching_test.rb.
key = key.to_s.dup
- key = key.force_encoding(ESCAPE_KEY_CHARS.encoding) if key.respond_to?(:encoding) && key.encoding != ESCAPE_KEY_CHARS.encoding
- key = key.gsub(ESCAPE_KEY_CHARS){|match| "%#{match.getbyte(0).to_s(16).upcase}"}
+ key = key.force_encoding("BINARY") if key.encoding_aware?
+ 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
end