From d0c745b8634be3bd830bc93998f199e18bebef49 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 18 Mar 2019 11:57:05 -0700 Subject: Remove virtual_path from fallback templates --- actionview/lib/action_view/template/resolver.rb | 24 ++++++++++++++-------- .../template/fallback_file_system_resolver_test.rb | 16 +++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 actionview/test/template/fallback_file_system_resolver_test.rb (limited to 'actionview') diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index 07c44307ff..1c577348e5 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -184,17 +184,21 @@ module ActionView template_paths = reject_files_external_to_app(template_paths) unless outside_app_allowed template_paths.map do |template| - handler, format, variant = extract_handler_and_format_and_variant(template) - - FileTemplate.new(File.expand_path(template), handler, - virtual_path: path.virtual, - format: format, - variant: variant, - locals: locals - ) + build_template(template, path.virtual, locals) end end + def build_template(template, virtual_path, locals) + handler, format, variant = extract_handler_and_format_and_variant(template) + + FileTemplate.new(File.expand_path(template), handler, + virtual_path: virtual_path, + format: format, + variant: variant, + locals: locals + ) + end + def reject_files_external_to_app(files) files.reject { |filename| !inside_path?(@path, filename) } end @@ -385,5 +389,9 @@ module ActionView def self.instances [new(""), new("/")] end + + def build_template(template, virtual_path, locals) + super(template, nil, locals) + end end end diff --git a/actionview/test/template/fallback_file_system_resolver_test.rb b/actionview/test/template/fallback_file_system_resolver_test.rb new file mode 100644 index 0000000000..304cdb8a03 --- /dev/null +++ b/actionview/test/template/fallback_file_system_resolver_test.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require "abstract_unit" + +class FallbackFileSystemResolverTest < ActiveSupport::TestCase + def setup + @root_resolver = ActionView::FallbackFileSystemResolver.new("/") + end + + def test_should_have_no_virtual_path + templates = @root_resolver.find_all("hello_world.erb", "#{FIXTURE_LOAD_PATH}/test", false, locale: [], formats: [:html], variants: [], handlers: [:erb]) + assert_equal 1, templates.size + assert_equal "Hello world!", templates[0].source + assert_nil templates[0].virtual_path + end +end -- cgit v1.2.3