From 08aeb01b0f681a706c173ec47a27e3b76a8011ba Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Sun, 31 May 2020 15:28:24 -0500 Subject: [PATCH] Lazily build path regex in PathParser Eagerly building the path regex can exclude handlers which are added on Action View load. Fixes #39492. --- actionview/lib/action_view/template/resolver.rb | 5 +---- railties/test/application/rendering_test.rb | 4 +++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index b04a7cab66..aefb3b19c0 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -36,10 +36,6 @@ module ActionView end class PathParser # :nodoc: - def initialize - @regex = build_path_regex - end - def build_path_regex handlers = Template::Handlers.extensions.map { |x| Regexp.escape(x) }.join("|") formats = Template::Types.symbols.map { |x| Regexp.escape(x) }.join("|") @@ -60,6 +56,7 @@ module ActionView end def parse(path) + @regex ||= build_path_regex match = @regex.match(path) { prefix: match[:prefix] || "", diff --git a/railties/test/application/rendering_test.rb b/railties/test/application/rendering_test.rb index bf2382695f..38cc3b75fe 100644 --- a/railties/test/application/rendering_test.rb +++ b/railties/test/application/rendering_test.rb @@ -77,7 +77,9 @@ module ApplicationTests source end end - ActionView::Template.register_template_handler(:rubby, RubbyHandler) + ActiveSupport.on_load :action_view do + ActionView::Template.register_template_handler(:rubby, RubbyHandler) + end RUBY get "/"