diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2012-08-02 12:43:14 -0700 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2012-08-02 12:43:14 -0700 |
commit | ac1a5d4234f7dc8463a9f3110086d6033eda34c7 (patch) | |
tree | a7d8de867da38f9e733f7a39660588ad223f5de1 /actionpack/lib/action_view | |
parent | d87524773d165ccd7292e61c4ee21be87f2b0703 (diff) | |
parent | a8d68d89e32f58397378bc3a27cb1391c95ab328 (diff) | |
download | rails-ac1a5d4234f7dc8463a9f3110086d6033eda34c7.tar.gz rails-ac1a5d4234f7dc8463a9f3110086d6033eda34c7.tar.bz2 rails-ac1a5d4234f7dc8463a9f3110086d6033eda34c7.zip |
Merge pull request #7129 from kennyj/fix_7079
Improve error handling when using partial name with hyphen. #7079
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/renderer/partial_renderer.rb | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index a08a566b35..128cade1b2 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -344,12 +344,6 @@ module ActionView paths.map! { |path| retrieve_variable(path).unshift(path) } end - if String === partial && @variable.to_s !~ /^[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 lowercase letter or underscore, " + - "and is followed by any combination of letters, numbers and underscores.") - end - self end @@ -456,8 +450,19 @@ module ActionView keys end + IDENTIFIER_ERROR_MESSAGE = "The partial name (%s) is not a valid Ruby identifier; " + + "make sure your partial name starts with a lowercase letter or underscore, " + + "and is followed by any combination of letters, numbers and underscores." + def retrieve_variable(path) - variable = @options.fetch(:as) { path[%r'_?(\w+)(\.\w+)*$', 1] }.try(:to_sym) + variable = if as = @options[:as] + raise ArgumentError.new(IDENTIFIER_ERROR_MESSAGE % (path)) unless as.to_s =~ /\A[a-z_]\w*\z/ + as.to_sym + else + base = path[-1] == "/" ? "" : File.basename(path) + raise ArgumentError.new(IDENTIFIER_ERROR_MESSAGE % (path)) unless base =~ /\A_?([a-z]\w*)(\.\w+)*\z/ + $1.to_sym + end variable_counter = :"#{variable}_counter" if @collection [variable, variable_counter] end |