From 7a3a40f037f45c2b77953571075bf8c029bae3ac Mon Sep 17 00:00:00 2001 From: Mohammed Siddick.E Date: Thu, 15 Jul 2010 17:51:15 +0530 Subject: [PATCH] Handle URI decode and Regex in expire_fragement --- actionpack/test/controller/caching_test.rb | 8 ++++++++ .../lib/active_support/cache/file_store.rb | 4 ++-- activesupport/test/caching_test.rb | 11 +++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index c161bea..cfccc8f 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -350,6 +350,14 @@ class ActionCacheTest < ActionController::TestCase assert_equal cached_time, @response.body end + def test_expire_fragment_with_url_regexp + get :show + assert_response :success + assert fragment_exist?('test.host/custom/show') + @controller.expire_fragment( /test\.host\/custom\/show/ ) + assert !fragment_exist?('test.host/custom/show') + end + def test_action_cache_with_custom_cache_path_in_block get :edit assert_response :success diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 84f6f29..70f1c59 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -12,7 +12,7 @@ module ActiveSupport DIR_FORMATTER = "%03X" ESCAPE_FILENAME_CHARS = /[^a-z0-9_.-]/i - UNESCAPE_FILENAME_CHARS = /%[0-9A-F]{2}/ + UNESCAPE_FILENAME_CHARS = /%([0-9A-F]{2})/ def initialize(cache_path, options = nil) super(options) @@ -156,7 +156,7 @@ module ActiveSupport # Translate a file path into a key. def file_path_key(path) fname = path[cache_path.size, path.size].split(File::SEPARATOR, 4).last - fname.gsub(UNESCAPE_FILENAME_CHARS){|match| $1.ord.to_s(16)} + fname.gsub(UNESCAPE_FILENAME_CHARS){|match| $1.hex.chr } end # Delete empty directories in the cache. diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 3e14c75..72e82a6 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -447,6 +447,17 @@ class FileStoreTest < ActiveSupport::TestCase include CacheDeleteMatchedBehavior include CacheIncrementDecrementBehavior + def test_delete_matched_with_url_regexp + @cache.write( 'localhost/blog/1?page=1', 'article 1,2,3,4,5' ) + @cache.write( 'localhost/blog/1?page=2', 'article 6,7,8,9' ) + assert_equal @cache.read( 'localhost/blog/1?page=1' ), 'article 1,2,3,4,5' + assert_equal @cache.read( 'localhost/blog/1?page=2' ), 'article 6,7,8,9' + + @cache.delete_matched(/^localhost\/blog\/1/) + assert_nil @cache.read( 'localhost/blog/1?page=1' ) + assert_nil @cache.read( 'localhost/blog/1?page=2' ) + end + def test_deprecated_expires_in_on_read ActiveSupport::Deprecation.silence do old_cache = ActiveSupport::Cache.lookup_store(:file_store, cache_dir) -- 1.6.5.3