aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-10-20 17:03:48 -0600
committerSean Griffin <sean@seantheprogrammer.com>2015-10-20 17:03:48 -0600
commit28129174f0b3eeaf644a7f00a89a76869960d672 (patch)
tree669e22f60b5fcf20f8c7b22f107fc584c2cbbaaa
parent6ae515d1bf1fe60527b010ffd35314470000e864 (diff)
parent2b5a8bc1868aedcd8dcb84c906792207282ae303 (diff)
downloadrails-28129174f0b3eeaf644a7f00a89a76869960d672.tar.gz
rails-28129174f0b3eeaf644a7f00a89a76869960d672.tar.bz2
rails-28129174f0b3eeaf644a7f00a89a76869960d672.zip
Merge pull request #19889 from cedrics/long-uri-encoded-keys
FileStore: Long cache keys may result in too long paths due to encoding
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb7
-rw-r--r--activesupport/test/caching_test.rb5
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 c235dee5e1..fb52613a23 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -762,6 +762,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)