Lazily build path regex in PathParser

Eagerly building the path regex can exclude handlers which are added on
Action View load.

Fixes #39492.
This commit is contained in:
Jonathan Hefner 2020-05-31 15:28:24 -05:00
parent ab06682534
commit 08aeb01b0f
2 changed files with 4 additions and 5 deletions

View File

@ -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] || "",

View File

@ -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 "/"