Skip to content
This repository
Browse code

Fix FileStore cache incorrectly regenerating its key from a pathname …

…when a regexp is used in expire_fragment

[#5850 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
commit ad2c0bdb9b94c79553e76f6b2db6fb23ccff6a97 1 parent f676beb
Denis Odorcic authored October 23, 2010 spastorino committed November 07, 2010
7  activesupport/lib/active_support/cache/file_store.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require 'active_support/core_ext/file/atomic'
2 2
 require 'active_support/core_ext/string/conversions'
  3
+require 'rack/utils'
3 4
 
4 5
 module ActiveSupport
5 6
   module Cache
@@ -11,8 +12,6 @@ class FileStore < Store
11 12
       attr_reader :cache_path
12 13
 
13 14
       DIR_FORMATTER = "%03X"
14  
-      ESCAPE_FILENAME_CHARS = /[^a-z0-9_.-]/i
15  
-      UNESCAPE_FILENAME_CHARS = /%[0-9A-F]{2}/
16 15
 
17 16
       def initialize(cache_path, options = nil)
18 17
         super(options)
@@ -136,7 +135,7 @@ def lock_file(file_name, &block) # :nodoc:
136 135
 
137 136
         # Translate a key into a file path.
138 137
         def key_file_path(key)
139  
-          fname = key.to_s.gsub(ESCAPE_FILENAME_CHARS){|match| "%#{match.ord.to_s(16).upcase}"}
  138
+          fname = Rack::Utils.escape(key)
140 139
           hash = Zlib.adler32(fname)
141 140
           hash, dir_1 = hash.divmod(0x1000)
142 141
           dir_2 = hash.modulo(0x1000)
@@ -156,7 +155,7 @@ def key_file_path(key)
156 155
         # Translate a file path into a key.
157 156
         def file_path_key(path)
158 157
           fname = path[cache_path.size, path.size].split(File::SEPARATOR, 4).last
159  
-          fname.gsub(UNESCAPE_FILENAME_CHARS){|match| $1.ord.to_s(16)}
  158
+          Rack::Utils.unescape(fname)
160 159
         end
161 160
 
162 161
         # Delete empty directories in the cache.
4  activesupport/test/caching_test.rb
@@ -356,9 +356,13 @@ module CacheDeleteMatchedBehavior
356 356
   def test_delete_matched
357 357
     @cache.write("foo", "bar")
358 358
     @cache.write("fu", "baz")
  359
+    @cache.write("foo/bar", "baz")
  360
+    @cache.write("fu/baz", "bar")
359 361
     @cache.delete_matched(/oo/)
360 362
     assert_equal false, @cache.exist?("foo")
361 363
     assert_equal true, @cache.exist?("fu")
  364
+    assert_equal false, @cache.exist?("foo/bar")
  365
+    assert_equal true, @cache.exist?("fu/baz")
362 366
   end
363 367
 end
364 368
 

0 notes on commit ad2c0bd

Please sign in to comment.
Something went wrong with that request. Please try again.