mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Redis cache store: fix expanding empty keys with no namespace
This commit is contained in:
parent
a1b6f08891
commit
8c4d6a04f8
2 changed files with 8 additions and 2 deletions
|
@ -444,11 +444,11 @@ module ActiveSupport
|
|||
|
||||
# Truncate keys that exceed 1kB.
|
||||
def normalize_key(key, options)
|
||||
truncate_key super.b
|
||||
truncate_key super&.b
|
||||
end
|
||||
|
||||
def truncate_key(key)
|
||||
if key.bytesize > max_key_bytesize
|
||||
if key && key.bytesize > max_key_bytesize
|
||||
suffix = ":sha2:#{::Digest::SHA2.hexdigest(key)}"
|
||||
truncate_at = max_key_bytesize - suffix.bytesize
|
||||
"#{key.byteslice(0, truncate_at)}#{suffix}"
|
||||
|
|
|
@ -110,6 +110,12 @@ module CacheStoreBehavior
|
|||
end
|
||||
end
|
||||
|
||||
def test_read_multi_with_empty_keys_and_a_logger_and_no_namespace
|
||||
@cache.options[:namespace] = nil
|
||||
@cache.logger = ActiveSupport::Logger.new(nil)
|
||||
assert_equal({}, @cache.read_multi)
|
||||
end
|
||||
|
||||
def test_fetch_multi
|
||||
@cache.write("foo", "bar")
|
||||
@cache.write("fud", "biz")
|
||||
|
|
Loading…
Reference in a new issue