diff options
Diffstat (limited to 'actionpack/lib')
4 files changed, 36 insertions, 47 deletions
diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index a6c17f50a5..4cba4f5f37 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -37,13 +37,7 @@ module ActionDispatch            path  = options[:script_name].to_s.chomp("/")            path << options[:path].to_s -          if options[:trailing_slash] -            if path.include?('?') -              path.sub!(/\?/, '/\&') -            else -              path.sub!(/[^\/]\z|\A\z/, '\&/') -            end -          end +          add_trailing_slash(path) if options[:trailing_slash]            result = path @@ -66,6 +60,18 @@ module ActionDispatch          private +        def add_trailing_slash(path) +          # includes querysting +          if path.include?('?') +            path.sub!(/\?/, '/\&') +          # does not have a .format +          elsif !path.include?(".") +            path.sub!(/[^\/]\z|\A\z/, '\&/') +          end + +          path +        end +          def build_host_url(options)            if match = options[:host].match(HOST_REGEXP)              options[:protocol] ||= match[1] unless options[:protocol] == false diff --git a/actionpack/lib/action_dispatch/journey/visualizer/index.html.erb b/actionpack/lib/action_dispatch/journey/visualizer/index.html.erb index 6aff10956a..9b28a65200 100644 --- a/actionpack/lib/action_dispatch/journey/visualizer/index.html.erb +++ b/actionpack/lib/action_dispatch/journey/visualizer/index.html.erb @@ -2,13 +2,13 @@  <html>    <head>      <title><%= title %></title> -    <link rel="stylesheet" href="https://raw.github.com/gist/1706081/af944401f75ea20515a02ddb3fb43d23ecb8c662/reset.css" type="text/css"> +    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.css" type="text/css">      <style>        <% stylesheets.each do |style| %>          <%= style %>        <% end %>      </style> -    <script src="https://raw.github.com/gist/1706081/df464722a05c3c2bec450b7b5c8240d9c31fa52d/d3.min.js" type="text/javascript"></script> +    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.8/d3.min.js" type="text/javascript"></script>    </head>    <body>      <div id="wrapper"> diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 7e78b417fa..f39fd1ea35 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -16,14 +16,6 @@ module ActionDispatch                         :shallow, :blocks, :defaults, :options]        class Constraints #:nodoc: -        def self.new(app, constraints, request = Rack::Request) -          if constraints.any? -            super(app, constraints, request) -          else -            app -          end -        end -          attr_reader :app, :constraints          def initialize(app, constraints, request) @@ -57,12 +49,18 @@ module ActionDispatch          WILDCARD_PATH = %r{\*([^/\)]+)\)?$}          attr_reader :scope, :path, :options, :requirements, :conditions, :defaults +        attr_reader :to, :default_controller, :default_action          def initialize(set, scope, path, options) -          @set, @scope, @path, @options = set, scope, path, options +          @set, @scope, @path = set, scope, path            @requirements, @conditions, @defaults = {}, {}, {} -          normalize_options! +          options = scope[:options].merge(options) if scope[:options] +          @to                 = options[:to] +          @default_controller = options[:controller] || scope[:controller] +          @default_action     = options[:action] || scope[:action] + +          @options = normalize_options!(options)            normalize_path!            normalize_requirements!            normalize_conditions! @@ -94,14 +92,13 @@ module ActionDispatch              options[:format] != false && !path.include?(':format') && !path.end_with?('/')            end -          def normalize_options! -            @options.reverse_merge!(scope[:options]) if scope[:options] +          def normalize_options!(options)              path_without_format = path.sub(/\(\.:format\)$/, '')              # Add a constraint for wildcard route to make it non-greedy and match the              # optional format part of the route by default -            if path_without_format.match(WILDCARD_PATH) && @options[:format] != false -              @options[$1.to_sym] ||= /.+?/ +            if path_without_format.match(WILDCARD_PATH) && options[:format] != false +              options[$1.to_sym] ||= /.+?/              end              if path_without_format.match(':controller') @@ -111,10 +108,10 @@ module ActionDispatch                # controllers with default routes like :controller/:action/:id(.:format), e.g:                # GET /admin/products/show/1                # => { controller: 'admin/products', action: 'show', id: '1' } -              @options[:controller] ||= /.+?/ +              options[:controller] ||= /.+?/              end -            @options.merge!(default_controller_and_action) +            options.merge!(default_controller_and_action)            end            def normalize_requirements! @@ -210,7 +207,11 @@ module ActionDispatch            end            def app -            Constraints.new(endpoint, blocks, @set.request_class) +            if blocks.any? +              Constraints.new(endpoint, blocks, @set.request_class) +            else +              endpoint +            end            end            def default_controller_and_action @@ -301,19 +302,7 @@ module ActionDispatch            end            def dispatcher -            Routing::RouteSet::Dispatcher.new(:defaults => defaults) -          end - -          def to -            options[:to] -          end - -          def default_controller -            options[:controller] || scope[:controller] -          end - -          def default_action -            options[:action] || scope[:action] +            Routing::RouteSet::Dispatcher.new(defaults)            end        end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index e9fb712a61..40c767e685 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -21,9 +21,8 @@ module ActionDispatch        PARAMETERS_KEY = 'action_dispatch.request.path_parameters'        class Dispatcher #:nodoc: -        def initialize(options={}) -          @defaults = options[:defaults] -          @glob_param = options.delete(:glob) +        def initialize(defaults) +          @defaults = defaults            @controller_class_names = ThreadSafe::Cache.new          end @@ -53,7 +52,6 @@ module ActionDispatch          def prepare_params!(params)            normalize_controller!(params)            merge_default_action!(params) -          split_glob_param!(params) if @glob_param          end          # If this is a default_controller (i.e. a controller specified by the user) @@ -89,10 +87,6 @@ module ActionDispatch          def merge_default_action!(params)            params[:action] ||= 'index'          end - -        def split_glob_param!(params) -          params[@glob_param] = params[@glob_param].split('/').map { |v| URI.parser.unescape(v) } -        end        end        # A NamedRouteCollection instance is a collection of named routes, and also  | 
