diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 4a13de98bc..25801128d0 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -884,7 +884,7 @@ def call(env) def recognize_path(path, environment = {}) method = (environment[:method] || "GET").to_s.upcase - path = Journey::Router::Utils.normalize_path(path) unless path.include?("://") + path = Journey::Router::Utils.normalize_path(path) unless path&.include?("://") extras = environment[:extras] || {} begin diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index e947d1c50e..d8f30cf7ba 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -2129,6 +2129,7 @@ def test_recognize_path assert_equal({ controller: "geocode", action: "show", postalcode: "12345" }, @routes.recognize_path("/extended/geocode/12345")) assert_equal({ controller: "news", action: "index" }, @routes.recognize_path("/", method: :get)) + assert_equal({ controller: "news", action: "index" }, @routes.recognize_path(nil)) assert_equal({ controller: "news", action: "index", format: "rss" }, @routes.recognize_path("/news.rss", method: :get)) assert_raise(ActionController::RoutingError) { @routes.recognize_path("/none", method: :get) }