Skip to content

Commit

Permalink
Merge pull request #41376 from fatkodima/memcached-normalize_key-nil
Browse files Browse the repository at this point in the history
Handle nil key for MemCacheStore#normalize_key
  • Loading branch information
rafaelfranca committed Feb 9, 2021
1 parent eeb5baa commit 5400804
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 8 additions & 4 deletions activesupport/lib/active_support/cache/mem_cache_store.rb
Expand Up @@ -185,10 +185,14 @@ def delete_entry(key, **options)
# before applying the regular expression to ensure we are escaping all
# characters properly.
def normalize_key(key, options)
key = super.dup
key = key.force_encoding(Encoding::ASCII_8BIT)
key = key.gsub(ESCAPE_KEY_CHARS) { |match| "%#{match.getbyte(0).to_s(16).upcase}" }
key = "#{key[0, 213]}:md5:#{ActiveSupport::Digest.hexdigest(key)}" if key.size > 250
key = super

if key
key = key.dup.force_encoding(Encoding::ASCII_8BIT)
key = key.gsub(ESCAPE_KEY_CHARS) { |match| "%#{match.getbyte(0).to_s(16).upcase}" }
key = "#{key[0, 213]}:md5:#{ActiveSupport::Digest.hexdigest(key)}" if key.size > 250
end

key
end

Expand Down
1 change: 0 additions & 1 deletion activesupport/test/cache/stores/mem_cache_store_test.rb
Expand Up @@ -45,7 +45,6 @@ def setup
@namespace = "test-#{SecureRandom.hex}"
@cache = lookup_store(expires_in: 60)
@peek = lookup_store
@cache.silence!
@cache.logger = ActiveSupport::Logger.new(File::NULL)
end

Expand Down

0 comments on commit 5400804

Please sign in to comment.