Merge pull request #37119 from jonathanhefner/fix-escaping-in-view-path-resolver

Fix escaping in OptimizedFileSystemResolver
This commit is contained in:
John Hawthorn 2019-09-10 17:36:22 -07:00 committed by GitHub
commit 2f44c3b00b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -350,7 +350,7 @@ module ActionView
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

View File

@ -79,6 +79,16 @@ module ResolverSharedTests
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!"