From 0671d8517749baccd993539407b8820e9da24290 Mon Sep 17 00:00:00 2001 From: Eric Hankins Date: Thu, 26 Feb 2015 16:28:09 -0600 Subject: [PATCH] Avoid infinite recursion when there is a redirect --- lib/apipie/application.rb | 7 ++++--- spec/dummy/config/routes.rb | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/apipie/application.rb b/lib/apipie/application.rb index 27704b6d..99daac3f 100644 --- a/lib/apipie/application.rb +++ b/lib/apipie/application.rb @@ -53,11 +53,12 @@ def rails_routes(route_set = nil) # the app might be nested when using contraints, namespaces etc. # this method does in depth search for the route controller - def route_app_controller(app, route) + def route_app_controller(app, route, visited_apps = []) + visited_apps << app if app.respond_to?(:controller) return app.controller(route.defaults) - elsif app.respond_to?(:app) - return route_app_controller(app.app, route) + elsif app.respond_to?(:app) && !visited_apps.include?(app.app) + return route_app_controller(app.app, route, visited_apps) end rescue ActionController::RoutingError # some errors in the routes will not stop us here: just ignoring diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb index 92bbab73..2d3d48b0 100644 --- a/spec/dummy/config/routes.rb +++ b/spec/dummy/config/routes.rb @@ -26,4 +26,5 @@ apipie end root :to => 'apipie/apipies#index' + match '(/)*path' => redirect('http://www.example.com'), :via => :all end