Permalink
Browse files

Ensure we are not calling length on nil.

  • Loading branch information...
1 parent 68a949b commit 82b700a89deffb6526f7fbfd9942f1e723cad9a7 @josevalim josevalim committed Aug 29, 2010
Showing with 4 additions and 5 deletions.
  1. +4 −5 railties/lib/rails/tasks/routes.rake
@@ -1,8 +1,7 @@
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
Rails.application.reload_routes!
-
- all_routes = Rails.application.routes.routes
+ all_routes = Rails.application.routes.routes
if ENV['CONTROLLER']
all_routes = all_routes.select{ |route| route.defaults[:controller] == ENV['CONTROLLER'] }
@@ -19,9 +18,9 @@ task :routes => :environment do
routes.reject! { |r| r[:path] =~ %r{/rails/info/properties} } # Skip the route if it's internal info route
- name_width = routes.map{ |r| r[:name] }.map(&:length).max
- verb_width = routes.map{ |r| r[:verb] }.map(&:length).max
- path_width = routes.map{ |r| r[:path] }.map(&:length).max
+ name_width = routes.map{ |r| r[:name].length if r[:name] }.max
+ verb_width = routes.map{ |r| r[:verb].length if r[:verb] }.max
+ path_width = routes.map{ |r| r[:path].length if r[:path] }.max
routes.each do |r|
puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
@ncook

ncook Aug 30, 2010

Surely the references to r[:name], r[:verb] and r[;path] need to be protected here too. rjust is not a method on nil.

@spastorino

spastorino Aug 31, 2010

Owner

ncook that was fixed by Sam Ruby in a later commit

@ncook

ncook Aug 31, 2010

Sorry - I did not image it could have been fixed so quickly - I should have checked.

0 comments on commit 82b700a

Please sign in to comment.