Skip to content

Commit

Permalink
Merge pull request #37119 from jonathanhefner/fix-escaping-in-view-pa…
Browse files Browse the repository at this point in the history
…th-resolver

Fix escaping in OptimizedFileSystemResolver
  • Loading branch information
jhawthorn committed Sep 11, 2019
2 parents da54c73 + 897cdc7 commit 2f44c3b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionview/lib/action_view/template/resolver.rb
Expand Up @@ -350,7 +350,7 @@ def find_template_paths_from_details(path, details)
end

def build_regex(path, details)
query = escape_entry(File.join(@path, path))
query = Regexp.escape(File.join(@path, path))
exts = EXTENSIONS.map do |ext, prefix|
match =
if ext == :variants && details[ext] == :any
Expand Down
10 changes: 10 additions & 0 deletions actionview/test/template/resolver_shared_tests.rb
Expand Up @@ -79,6 +79,16 @@ def test_can_find_with_any_variant_format_and_handler
assert_kind_of ActionView::Template::Handlers::ERB, templates[0].handler
end

def test_can_find_when_special_chars_in_path
dir = "test +()[]{}"
with_file "#{dir}/hello_world", "Hello funky path!"

templates = resolver.find_all("hello_world", dir, false, locale: [:en], formats: [:html], variants: [:phone], handlers: [:erb])
assert_equal 1, templates.size
assert_equal "Hello funky path!", templates[0].source
assert_equal "#{dir}/hello_world", templates[0].virtual_path
end

def test_doesnt_find_template_with_wrong_details
with_file "test/hello_world.html.erb", "Hello plain text!"

Expand Down

0 comments on commit 2f44c3b

Please sign in to comment.