Permalink
Browse files

Tidy up previous commit.

  • Loading branch information...
1 parent 182d008 commit bb44cd727ff4df0c6baac52ec008289626b874e9 @josevalim josevalim committed Apr 28, 2011
Showing with 8 additions and 3 deletions.
  1. +8 −3 activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -4,7 +4,9 @@
$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 @@ def delete_entry(key, options) # :nodoc:
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

0 comments on commit bb44cd7

Please sign in to comment.