Skip to content

Commit

Permalink
Merge pull request #39143 from JackMc/add-separator-cachingkeygenerator
Browse files Browse the repository at this point in the history
Add a separator to the cache key for ActiveSupport::CachingKeyGenerator
  • Loading branch information
tenderlove committed May 4, 2020
2 parents e55fb52 + dd870dd commit 351e38d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/key_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def initialize(key_generator)

# Returns a derived key suitable for use.
def generate_key(*args)
@cache_keys[args.join] ||= @key_generator.generate_key(*args)
@cache_keys[args.join('|')] ||= @key_generator.generate_key(*args)
end
end
end
7 changes: 7 additions & 0 deletions activesupport/test/key_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ def setup

assert_not_equal derived_key, different_length_key
end

test "Does not cache key for different salts and lengths that are different but are equal when concatenated" do
derived_key = @caching_generator.generate_key("13", 37)
different_length_key = @caching_generator.generate_key("1", 337)

assert_not_equal derived_key, different_length_key
end
end

end

0 comments on commit 351e38d

Please sign in to comment.