aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorbrainopia <brainopia@evilmartians.com>2015-02-23 19:51:30 +0300
committerbrainopia <brainopia@evilmartians.com>2015-02-23 19:57:01 +0300
commit321db4aa2edf46b8cf54c99bf3b97b48b7099dcf (patch)
treec2a07a82692e7c5ed546c02e7340ccb429d62842 /railties
parente71f5dad4e0d27afbcc091173bee20bd6f4d2a4e (diff)
downloadrails-321db4aa2edf46b8cf54c99bf3b97b48b7099dcf.tar.gz
rails-321db4aa2edf46b8cf54c99bf3b97b48b7099dcf.tar.bz2
rails-321db4aa2edf46b8cf54c99bf3b97b48b7099dcf.zip
Change filter on /rails/info/routes to use an actual path regexp from rails
Change filter on /rails/info/routes to use an actual path regexp from rails and not approximate javascript version. Oniguruma supports much more extensive list of features than javascript regexp engine. Fixes #18402.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/info_controller.rb25
-rw-r--r--railties/test/rails_info_controller_test.rb25
2 files changed, 48 insertions, 2 deletions
diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb
index 49e5431a16..6e61cc3cb5 100644
--- a/railties/lib/rails/info_controller.rb
+++ b/railties/lib/rails/info_controller.rb
@@ -17,7 +17,28 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
end
def routes
- @routes_inspector = ActionDispatch::Routing::RoutesInspector.new(_routes.routes)
- @page_title = 'Routes'
+ if path = params[:path]
+ path = URI.escape path
+ normalized_path = with_leading_slash path
+ render json: {
+ exact: match_route {|it| it.match normalized_path },
+ fuzzy: match_route {|it| it.spec.to_s.match path }
+ }
+ else
+ @routes_inspector = ActionDispatch::Routing::RoutesInspector.new(_routes.routes)
+ @page_title = 'Routes'
+ end
+ end
+
+ private
+
+ def match_route
+ _routes.routes.select {|route|
+ yield route.path
+ }.map {|route| route.path.spec.to_s }
+ end
+
+ def with_leading_slash(path)
+ ('/' + path).squeeze('/')
end
end
diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb
index 25b0e761cb..d87b51d852 100644
--- a/railties/test/rails_info_controller_test.rb
+++ b/railties/test/rails_info_controller_test.rb
@@ -53,4 +53,29 @@ class InfoControllerTest < ActionController::TestCase
assert_response :success
end
+ test "info controller returns exact matches" do
+ exact_count = -> { JSON(response.body)['exact'].size }
+
+ get :routes, path: 'rails/info/route'
+ assert exact_count.call == 0, 'should not match incomplete routes'
+
+ get :routes, path: 'rails/info/routes'
+ assert exact_count.call == 1, 'should match complete routes'
+
+ get :routes, path: 'rails/info/routes.html'
+ assert exact_count.call == 1, 'should match complete routes with optional parts'
+ end
+
+ test "info controller returns fuzzy matches" do
+ fuzzy_count = -> { JSON(response.body)['fuzzy'].size }
+
+ get :routes, path: 'rails/info'
+ assert fuzzy_count.call == 2, 'should match incomplete routes'
+
+ get :routes, path: 'rails/info/routes'
+ assert fuzzy_count.call == 1, 'should match complete routes'
+
+ get :routes, path: 'rails/info/routes.html'
+ assert fuzzy_count.call == 0, 'should match optional parts of route literally'
+ end
end