diff options
author | brainopia <brainopia@evilmartians.com> | 2015-02-23 19:51:30 +0300 |
---|---|---|
committer | brainopia <brainopia@evilmartians.com> | 2015-02-23 19:57:01 +0300 |
commit | 321db4aa2edf46b8cf54c99bf3b97b48b7099dcf (patch) | |
tree | c2a07a82692e7c5ed546c02e7340ccb429d62842 /railties/lib | |
parent | e71f5dad4e0d27afbcc091173bee20bd6f4d2a4e (diff) | |
download | rails-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/lib')
-rw-r--r-- | railties/lib/rails/info_controller.rb | 25 |
1 files changed, 23 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 |