mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Merge pull request #2018 from bhus/render_partial_invalid_check
Render partial invalid check
This commit is contained in:
@@ -301,6 +301,12 @@ module ActionView
|
||||
paths.map! { |path| retrieve_variable(path).unshift(path) }
|
||||
end
|
||||
|
||||
if String === partial && @variable !~ /^[a-z_][a-zA-Z_0-9]*$/
|
||||
raise ArgumentError.new("The partial name (#{partial}) is not a valid Ruby identifier; " +
|
||||
"make sure your partial name starts with a letter or underscore, " +
|
||||
"and is followed by any combinations of letters, numbers, or underscores.")
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
|
||||
1
actionpack/test/fixtures/test/_200.html.erb
vendored
Normal file
1
actionpack/test/fixtures/test/_200.html.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Invalid partial</h1>
|
||||
@@ -98,6 +98,15 @@ module RenderTestCases
|
||||
assert_equal "only partial", @view.render("test/partial_only", :counter_counter => 5)
|
||||
end
|
||||
|
||||
def test_render_partial_with_invalid_name
|
||||
@view.render(:partial => "test/200")
|
||||
flunk "Render did not raise ArgumentError"
|
||||
rescue ArgumentError => e
|
||||
assert_equal "The partial name (test/200) is not a valid Ruby identifier; " +
|
||||
"make sure your partial name starts with a letter or underscore, " +
|
||||
"and is followed by any combinations of letters, numbers, or underscores.", e.message
|
||||
end
|
||||
|
||||
def test_render_partial_with_errors
|
||||
@view.render(:partial => "test/raise")
|
||||
flunk "Render did not raise Template::Error"
|
||||
|
||||
Reference in New Issue
Block a user