diff options
author | Cedric Sohrauer <cedric.sohrauer@infopark.de> | 2015-04-23 15:44:33 +0200 |
---|---|---|
committer | Cedric Sohrauer <cedric.sohrauer@infopark.de> | 2015-04-24 15:36:40 +0200 |
commit | 2b5a8bc1868aedcd8dcb84c906792207282ae303 (patch) | |
tree | d07683a68f6e657e7deba77780523b0ee8e9e89a | |
parent | b29d794b8cdf59896e668a0f68038dd25228398e (diff) | |
download | rails-2b5a8bc1868aedcd8dcb84c906792207282ae303.tar.gz rails-2b5a8bc1868aedcd8dcb84c906792207282ae303.tar.bz2 rails-2b5a8bc1868aedcd8dcb84c906792207282ae303.zip |
when checking for too long cache keys used the uri encoded fname
-rw-r--r-- | activesupport/lib/active_support/cache/file_store.rb | 7 | ||||
-rw-r--r-- | activesupport/test/caching_test.rb | 5 |
2 files changed, 9 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index e6a8b84214..b7da30123a 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -119,11 +119,12 @@ module ActiveSupport # Translate a key into a file path. def key_file_path(key) - if key.size > FILEPATH_MAX_SIZE - key = Digest::MD5.hexdigest(key) + fname = URI.encode_www_form_component(key) + + if fname.size > FILEPATH_MAX_SIZE + fname = Digest::MD5.hexdigest(key) end - fname = URI.encode_www_form_component(key) hash = Zlib.adler32(fname) hash, dir_1 = hash.divmod(0x1000) dir_2 = hash.modulo(0x1000) diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 527538ed9a..22a3bd0b9a 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -714,6 +714,11 @@ class FileStoreTest < ActiveSupport::TestCase assert_equal 1, @cache.read("a"*10000) end + def test_long_uri_encoded_keys + @cache.write("%"*870, 1) + assert_equal 1, @cache.read("%"*870) + end + def test_key_transformation key = @cache.send(:key_file_path, "views/index?id=1") assert_equal "views/index?id=1", @cache.send(:file_path_key, key) |