From d51e2eefd5c50cef366ddc96a3b93af0395755f1 Mon Sep 17 00:00:00 2001 From: Dov Murik Date: Mon, 1 Jun 2015 21:56:31 -0400 Subject: Improve detection of partial templates eligible for collection caching. The regular expression which was used to detect partial templates that begin with a `<% cache ... do %>` call missed some cases. This commits attempts to improve the detection for some cases such as multi-line comments at the beginning of the template. The different templates are listed in two new unit test methods. Note that specially crafted Ruby code can still evade such `cache`-call detection: for example, a user might have its own method which itself calls the Rails `cache` helper. In such a case, the template's code doesn't start with a literal `cache` string and therefore will not be eligible for collection caching. --- actionview/lib/action_view/template/handlers/erb.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview/lib/action_view/template/handlers') diff --git a/actionview/lib/action_view/template/handlers/erb.rb b/actionview/lib/action_view/template/handlers/erb.rb index 88a8570706..da96347e4d 100644 --- a/actionview/lib/action_view/template/handlers/erb.rb +++ b/actionview/lib/action_view/template/handlers/erb.rb @@ -138,7 +138,7 @@ module ActionView # # <% cache notification.event do %> # => nil def resource_cache_call_pattern - /\A(?:<%#.*%>\n?)?<% cache\(?\s*(\w+\.?)/ + /\A(?:<%#.*%>)*\s*<%\s*cache\(?\s*(\w+)[\s\)]/m end private -- cgit v1.2.3