Permalink
Browse files

Dots in template path should not trip up rendering (closes #4244) [lm…

…arlow@yahoo.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3884 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
dhh committed Mar 16, 2006
1 parent 500c734 commit 7d06259be9b1b20816dd3502a0fd6f311ef6b24b
@@ -221,7 +221,7 @@ def render_file(template_path, use_full_path = true, local_assigns = {})
@first_render = template_path if @first_render.nil?
if use_full_path
- template_path_without_extension, template_extension = template_path.split('.')
+ template_path_without_extension, template_extension = path_and_extension(template_path)
if template_extension
template_file_name = full_template_path(template_path_without_extension, template_extension)
@@ -335,7 +335,7 @@ def javascript_template_exists?(template_path)#:nodoc:
end
def file_exists?(template_path)#:nodoc:
- template_file_name, template_file_extension = template_path.split(".")
+ template_file_name, template_file_extension = path_and_extension(template_path)
if template_file_extension
template_exists?(template_file_name, template_file_extension)
@@ -361,6 +361,11 @@ def template_exists?(template_path, extension)
@@method_names.has_key?(file_path) || FileTest.exists?(file_path)
end
+ def path_and_extension(template_path)
+ template_path_without_extension = template_path.sub(/\.(\w+)$/, '')
+ [ template_path_without_extension, $1 ]
+ end
+
# This method reads a template file.
def read_template_file(template_path, extension)
File.read(template_path)
@@ -73,7 +73,17 @@ def render_file_not_using_full_path
@secret = 'in the sauce'
render :file => 'test/render_file_with_ivar', :use_full_path => true
end
+
+ def render_file_not_using_full_path_with_relative_path
+ @secret = 'in the sauce'
+ render :file => 'test/../test/render_file_with_ivar', :use_full_path => true
+ end
+ def render_file_not_using_full_path_with_dot_in_path
+ @secret = 'in the sauce'
+ render :file => 'test/dot.directory/render_file_with_ivar', :use_full_path => true
+ end
+
def render_xml_hello
@name = "David"
render :template => "test/hello"
@@ -353,6 +363,16 @@ def test_render_file_not_using_full_path
assert_equal "The secret is in the sauce\n", @response.body
end
+ def test_render_file_not_using_full_path_with_relative_path
+ get :render_file_not_using_full_path_with_relative_path
+ assert_equal "The secret is in the sauce\n", @response.body
+ end
+
+ def test_render_file_not_using_full_path_with_dot_in_path
+ get :render_file_not_using_full_path_with_dot_in_path
+ assert_equal "The secret is in the sauce\n", @response.body
+ end
+
def test_render_file_with_locals
get :render_file_with_locals
assert_equal "The secret is in the sauce\n", @response.body
@@ -577,4 +597,4 @@ def test_overwritting_rendering_relative_file_with_extension
get :hello_world_from_rxml_using_action
assert_equal "<html>\n <p>Hello</p>\n</html>\n", @response.body
end
-end
+end
@@ -0,0 +1 @@
+The secret is <%= @secret %>

0 comments on commit 7d06259

Please sign in to comment.