actionpack 8.0.5.2 → 8.1.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +231 -277
  3. data/lib/abstract_controller/asset_paths.rb +4 -2
  4. data/lib/abstract_controller/base.rb +10 -2
  5. data/lib/abstract_controller/caching.rb +6 -3
  6. data/lib/abstract_controller/helpers.rb +1 -1
  7. data/lib/abstract_controller/logger.rb +2 -1
  8. data/lib/action_controller/base.rb +1 -1
  9. data/lib/action_controller/caching.rb +1 -2
  10. data/lib/action_controller/form_builder.rb +1 -1
  11. data/lib/action_controller/log_subscriber.rb +7 -0
  12. data/lib/action_controller/metal/allow_browser.rb +1 -1
  13. data/lib/action_controller/metal/conditional_get.rb +25 -0
  14. data/lib/action_controller/metal/data_streaming.rb +1 -3
  15. data/lib/action_controller/metal/exceptions.rb +5 -0
  16. data/lib/action_controller/metal/flash.rb +1 -4
  17. data/lib/action_controller/metal/head.rb +3 -1
  18. data/lib/action_controller/metal/live.rb +5 -52
  19. data/lib/action_controller/metal/permissions_policy.rb +9 -0
  20. data/lib/action_controller/metal/rate_limiting.rb +22 -7
  21. data/lib/action_controller/metal/redirecting.rb +61 -5
  22. data/lib/action_controller/metal/renderers.rb +27 -6
  23. data/lib/action_controller/metal/rendering.rb +9 -10
  24. data/lib/action_controller/metal/request_forgery_protection.rb +18 -10
  25. data/lib/action_controller/metal/rescue.rb +9 -0
  26. data/lib/action_controller/metal/strong_parameters.rb +8 -16
  27. data/lib/action_controller/railtie.rb +2 -11
  28. data/lib/action_dispatch/http/cache.rb +111 -1
  29. data/lib/action_dispatch/http/filter_parameters.rb +5 -3
  30. data/lib/action_dispatch/http/mime_negotiation.rb +1 -11
  31. data/lib/action_dispatch/http/mime_types.rb +1 -0
  32. data/lib/action_dispatch/http/param_builder.rb +28 -27
  33. data/lib/action_dispatch/http/parameters.rb +3 -3
  34. data/lib/action_dispatch/http/permissions_policy.rb +4 -0
  35. data/lib/action_dispatch/http/query_parser.rb +12 -10
  36. data/lib/action_dispatch/http/request.rb +10 -5
  37. data/lib/action_dispatch/http/response.rb +16 -3
  38. data/lib/action_dispatch/http/url.rb +99 -3
  39. data/lib/action_dispatch/journey/gtg/simulator.rb +33 -12
  40. data/lib/action_dispatch/journey/gtg/transition_table.rb +33 -43
  41. data/lib/action_dispatch/journey/nodes/node.rb +2 -1
  42. data/lib/action_dispatch/journey/route.rb +45 -31
  43. data/lib/action_dispatch/journey/router/utils.rb +8 -14
  44. data/lib/action_dispatch/journey/router.rb +59 -81
  45. data/lib/action_dispatch/journey/routes.rb +7 -0
  46. data/lib/action_dispatch/journey/visitors.rb +55 -23
  47. data/lib/action_dispatch/journey/visualizer/fsm.js +4 -6
  48. data/lib/action_dispatch/middleware/cookies.rb +5 -18
  49. data/lib/action_dispatch/middleware/debug_exceptions.rb +8 -2
  50. data/lib/action_dispatch/middleware/debug_view.rb +11 -0
  51. data/lib/action_dispatch/middleware/exception_wrapper.rb +11 -5
  52. data/lib/action_dispatch/middleware/executor.rb +12 -2
  53. data/lib/action_dispatch/middleware/public_exceptions.rb +1 -5
  54. data/lib/action_dispatch/middleware/session/abstract_store.rb +0 -5
  55. data/lib/action_dispatch/middleware/session/cache_store.rb +16 -22
  56. data/lib/action_dispatch/middleware/session/cookie_store.rb +3 -0
  57. data/lib/action_dispatch/middleware/templates/rescues/_copy_button.html.erb +1 -0
  58. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +3 -2
  59. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +9 -5
  60. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +1 -0
  61. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +1 -0
  62. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +1 -0
  63. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +50 -0
  64. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +1 -0
  65. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -0
  66. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +1 -0
  67. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -0
  68. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -0
  69. data/lib/action_dispatch/railtie.rb +10 -2
  70. data/lib/action_dispatch/routing/inspector.rb +4 -1
  71. data/lib/action_dispatch/routing/mapper.rb +323 -173
  72. data/lib/action_dispatch/routing/route_set.rb +2 -4
  73. data/lib/action_dispatch/routing/routes_proxy.rb +0 -1
  74. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +2 -2
  75. data/lib/action_dispatch/testing/assertions/response.rb +14 -0
  76. data/lib/action_dispatch/testing/assertions/routing.rb +11 -3
  77. data/lib/action_dispatch/testing/integration.rb +7 -7
  78. data/lib/action_dispatch/testing/request_encoder.rb +9 -9
  79. data/lib/action_pack/gem_version.rb +3 -3
  80. metadata +12 -11
@@ -71,32 +71,39 @@ module ActionController # :nodoc:
71
71
  included do
72
72
  # Sets the token parameter name for RequestForgery. Calling
73
73
  # `protect_from_forgery` sets it to `:authenticity_token` by default.
74
- config_accessor :request_forgery_protection_token
74
+ singleton_class.delegate :request_forgery_protection_token, :request_forgery_protection_token=, to: :config
75
+ delegate :request_forgery_protection_token, :request_forgery_protection_token=, to: :config
75
76
  self.request_forgery_protection_token ||= :authenticity_token
76
77
 
77
78
  # Holds the class which implements the request forgery protection.
78
- config_accessor :forgery_protection_strategy
79
+ singleton_class.delegate :forgery_protection_strategy, :forgery_protection_strategy=, to: :config
80
+ delegate :forgery_protection_strategy, :forgery_protection_strategy=, to: :config
79
81
  self.forgery_protection_strategy = nil
80
82
 
81
83
  # Controls whether request forgery protection is turned on or not. Turned off by
82
84
  # default only in test mode.
83
- config_accessor :allow_forgery_protection
85
+ singleton_class.delegate :allow_forgery_protection, :allow_forgery_protection=, to: :config
86
+ delegate :allow_forgery_protection, :allow_forgery_protection=, to: :config
84
87
  self.allow_forgery_protection = true if allow_forgery_protection.nil?
85
88
 
86
89
  # Controls whether a CSRF failure logs a warning. On by default.
87
- config_accessor :log_warning_on_csrf_failure
90
+ singleton_class.delegate :log_warning_on_csrf_failure, :log_warning_on_csrf_failure=, to: :config
91
+ delegate :log_warning_on_csrf_failure, :log_warning_on_csrf_failure=, to: :config
88
92
  self.log_warning_on_csrf_failure = true
89
93
 
90
94
  # Controls whether the Origin header is checked in addition to the CSRF token.
91
- config_accessor :forgery_protection_origin_check
95
+ singleton_class.delegate :forgery_protection_origin_check, :forgery_protection_origin_check=, to: :config
96
+ delegate :forgery_protection_origin_check, :forgery_protection_origin_check=, to: :config
92
97
  self.forgery_protection_origin_check = false
93
98
 
94
99
  # Controls whether form-action/method specific CSRF tokens are used.
95
- config_accessor :per_form_csrf_tokens
100
+ singleton_class.delegate :per_form_csrf_tokens, :per_form_csrf_tokens=, to: :config
101
+ delegate :per_form_csrf_tokens, :per_form_csrf_tokens=, to: :config
96
102
  self.per_form_csrf_tokens = false
97
103
 
98
104
  # The strategy to use for storing and retrieving CSRF tokens.
99
- config_accessor :csrf_token_storage_strategy
105
+ singleton_class.delegate :csrf_token_storage_strategy, :csrf_token_storage_strategy=, to: :config
106
+ delegate :csrf_token_storage_strategy, :csrf_token_storage_strategy=, to: :config
100
107
  self.csrf_token_storage_strategy = SessionStore.new
101
108
 
102
109
  helper_method :form_authenticity_token
@@ -461,7 +468,7 @@ module ActionController # :nodoc:
461
468
  # * Does the `X-CSRF-Token` header match the form_authenticity_token?
462
469
  #
463
470
  def verified_request? # :doc:
464
- !protect_against_forgery? || request.get? || request.head? ||
471
+ request.get? || request.head? || !protect_against_forgery? ||
465
472
  (valid_request_origin? && any_authenticity_token_valid?)
466
473
  end
467
474
 
@@ -621,6 +628,7 @@ module ActionController # :nodoc:
621
628
  If you cannot change the referrer policy, you can disable origin checking with the
622
629
  Rails.application.config.action_controller.forgery_protection_origin_check setting.
623
630
  MSG
631
+ private_constant :NULL_ORIGIN_MESSAGE
624
632
 
625
633
  # Checks if the request originated from the same origin by looking at the Origin
626
634
  # header.
@@ -634,7 +642,7 @@ module ActionController # :nodoc:
634
642
  end
635
643
  end
636
644
 
637
- def normalize_action_path(action_path) # :doc:
645
+ def normalize_action_path(action_path)
638
646
  uri = URI.parse(action_path)
639
647
 
640
648
  if uri.relative? && (action_path.blank? || !action_path.start_with?("/"))
@@ -644,7 +652,7 @@ module ActionController # :nodoc:
644
652
  end
645
653
  end
646
654
 
647
- def normalize_relative_action_path(rel_action_path) # :doc:
655
+ def normalize_relative_action_path(rel_action_path)
648
656
  uri = URI.parse(request.path)
649
657
  # add the action path to the request.path
650
658
  uri.path += "/#{rel_action_path}"
@@ -13,6 +13,15 @@ module ActionController # :nodoc:
13
13
  extend ActiveSupport::Concern
14
14
  include ActiveSupport::Rescuable
15
15
 
16
+ module ClassMethods
17
+ def handler_for_rescue(exception, ...) # :nodoc:
18
+ if handler = super
19
+ ActiveSupport::Notifications.instrument("rescue_from_callback.action_controller", exception: exception)
20
+ handler
21
+ end
22
+ end
23
+ end
24
+
16
25
  # Override this method if you want to customize when detailed exceptions must be
17
26
  # shown. This method is only called when `consider_all_requests_local` is
18
27
  # `false`. By default, it returns `false`, but someone may set it to
@@ -197,14 +197,15 @@ module ActionController
197
197
  # as_json(options=nil)
198
198
  #
199
199
  # Returns a hash that can be used as the JSON representation for the parameters.
200
+
201
+ ##
202
+ # :method: each_key
200
203
  #
201
- # Like `#to_unsafe_h`, the hash holds every parameter, permitted or not, and
202
- # mass assignment does not check it. Do not pass it to a model.
204
+ # :call-seq:
205
+ # each_key(&block)
203
206
  #
204
- # params = ActionController::Parameters.new(name: "Bob", admin: true)
205
- # params.as_json # => {"name" => "Bob", "admin" => true}
206
- # User.new(params) # => ActiveModel::ForbiddenAttributesError
207
- # User.new(params.as_json) # => #<User name: "Bob", admin: true>
207
+ # Calls block once for each key in the parameters, passing the key. If no block
208
+ # is given, an enumerator is returned instead.
208
209
 
209
210
  ##
210
211
  # :method: empty?
@@ -247,7 +248,7 @@ module ActionController
247
248
  # Returns the content of the parameters as a string.
248
249
 
249
250
  delegate :keys, :empty?, :exclude?, :include?,
250
- :as_json, :to_s, to: :@parameters
251
+ :as_json, :to_s, :each_key, to: :@parameters
251
252
 
252
253
  alias_method :has_key?, :include?
253
254
  alias_method :key?, :include?
@@ -419,15 +420,6 @@ module ActionController
419
420
  self
420
421
  end
421
422
 
422
- # Calls block once for each key in the parameters, passing the key. If no block
423
- # is given, an enumerator is returned instead.
424
- def each_key(&block)
425
- return to_enum(:each_key) unless block_given?
426
- @parameters.each_key(&block)
427
-
428
- self
429
- end
430
-
431
423
  # Returns a new array of the values of the parameters.
432
424
  def values
433
425
  to_enum(:each_value).to_a
@@ -13,8 +13,10 @@ module ActionController
13
13
  class Railtie < Rails::Railtie # :nodoc:
14
14
  config.action_controller = ActiveSupport::OrderedOptions.new
15
15
  config.action_controller.raise_on_open_redirects = false
16
+ config.action_controller.action_on_path_relative_redirect = :log
16
17
  config.action_controller.log_query_tags_around_actions = true
17
18
  config.action_controller.wrap_parameters_by_default = false
19
+ config.action_controller.allowed_redirect_hosts = []
18
20
 
19
21
  config.eager_load_namespaces << AbstractController
20
22
  config.eager_load_namespaces << ActionController
@@ -31,10 +33,6 @@ module ActionController
31
33
  ActionController::Helpers.helpers_path = app.helpers_paths
32
34
  end
33
35
 
34
- initializer "action_controller.live_streaming_excluded_keys" do |app|
35
- ActionController::Live.live_streaming_excluded_keys = app.config.action_controller.live_streaming_excluded_keys
36
- end
37
-
38
36
  initializer "action_controller.parameters_config" do |app|
39
37
  options = app.config.action_controller
40
38
 
@@ -84,7 +82,6 @@ module ActionController
84
82
  :action_on_unpermitted_parameters,
85
83
  :always_permitted_parameters,
86
84
  :wrap_parameters_by_default,
87
- :live_streaming_excluded_keys
88
85
  )
89
86
 
90
87
  filtered_options.each do |k, v|
@@ -98,12 +95,6 @@ module ActionController
98
95
  end
99
96
  end
100
97
 
101
- initializer "action_controller.compile_config_methods" do
102
- ActiveSupport.on_load(:action_controller) do
103
- config.compile_methods! if config.respond_to?(:compile_methods!)
104
- end
105
- end
106
-
107
98
  initializer "action_controller.request_forgery_protection" do |app|
108
99
  ActiveSupport.on_load(:action_controller_base) do
109
100
  if app.config.action_controller.default_protect_from_forgery
@@ -63,6 +63,114 @@ module ActionDispatch
63
63
  success
64
64
  end
65
65
  end
66
+
67
+ def cache_control_directives
68
+ @cache_control_directives ||= CacheControlDirectives.new(get_header("HTTP_CACHE_CONTROL"))
69
+ end
70
+
71
+ # Represents the HTTP Cache-Control header for requests,
72
+ # providing methods to access various cache control directives
73
+ # Reference: https://www.rfc-editor.org/rfc/rfc9111.html#name-request-directives
74
+ class CacheControlDirectives
75
+ def initialize(cache_control_header)
76
+ @only_if_cached = false
77
+ @no_cache = false
78
+ @no_store = false
79
+ @no_transform = false
80
+ @max_age = nil
81
+ @max_stale = nil
82
+ @min_fresh = nil
83
+ @stale_if_error = false
84
+ parse_directives(cache_control_header)
85
+ end
86
+
87
+ # Returns true if the only-if-cached directive is present.
88
+ # This directive indicates that the client only wishes to obtain a
89
+ # stored response. If a valid stored response is not available,
90
+ # the server should respond with a 504 (Gateway Timeout) status.
91
+ def only_if_cached?
92
+ @only_if_cached
93
+ end
94
+
95
+ # Returns true if the no-cache directive is present.
96
+ # This directive indicates that a cache must not use the response
97
+ # to satisfy subsequent requests without successful validation on the origin server.
98
+ def no_cache?
99
+ @no_cache
100
+ end
101
+
102
+ # Returns true if the no-store directive is present.
103
+ # This directive indicates that a cache must not store any part of the
104
+ # request or response.
105
+ def no_store?
106
+ @no_store
107
+ end
108
+
109
+ # Returns true if the no-transform directive is present.
110
+ # This directive indicates that a cache or proxy must not transform the payload.
111
+ def no_transform?
112
+ @no_transform
113
+ end
114
+
115
+ # Returns the value of the max-age directive.
116
+ # This directive indicates that the client is willing to accept a response
117
+ # whose age is no greater than the specified number of seconds.
118
+ attr_reader :max_age
119
+
120
+ # Returns the value of the max-stale directive.
121
+ # When max-stale is present with a value, returns that integer value.
122
+ # When max-stale is present without a value, returns true (unlimited staleness).
123
+ # When max-stale is not present, returns nil.
124
+ attr_reader :max_stale
125
+
126
+ # Returns true if max-stale directive is present (with or without a value)
127
+ def max_stale?
128
+ !@max_stale.nil?
129
+ end
130
+
131
+ # Returns true if max-stale directive is present without a value (unlimited staleness)
132
+ def max_stale_unlimited?
133
+ @max_stale == true
134
+ end
135
+
136
+ # Returns the value of the min-fresh directive.
137
+ # This directive indicates that the client is willing to accept a response
138
+ # whose freshness lifetime is no less than its current age plus the specified time in seconds.
139
+ attr_reader :min_fresh
140
+
141
+ # Returns the value of the stale-if-error directive.
142
+ # This directive indicates that the client is willing to accept a stale response
143
+ # if the check for a fresh one fails with an error for the specified number of seconds.
144
+ attr_reader :stale_if_error
145
+
146
+ private
147
+ def parse_directives(header_value)
148
+ return unless header_value
149
+
150
+ header_value.delete(" ").downcase.split(",").each do |directive|
151
+ name, value = directive.split("=", 2)
152
+
153
+ case name
154
+ when "max-age"
155
+ @max_age = value.to_i
156
+ when "min-fresh"
157
+ @min_fresh = value.to_i
158
+ when "stale-if-error"
159
+ @stale_if_error = value.to_i
160
+ when "no-cache"
161
+ @no_cache = true
162
+ when "no-store"
163
+ @no_store = true
164
+ when "no-transform"
165
+ @no_transform = true
166
+ when "only-if-cached"
167
+ @only_if_cached = true
168
+ when "max-stale"
169
+ @max_stale = value ? value.to_i : true
170
+ end
171
+ end
172
+ end
173
+ end
66
174
  end
67
175
 
68
176
  module Response
@@ -142,7 +250,7 @@ module ActionDispatch
142
250
  private
143
251
  DATE = "Date"
144
252
  LAST_MODIFIED = "Last-Modified"
145
- SPECIAL_KEYS = Set.new(%w[extras no-store no-cache max-age public private must-revalidate])
253
+ SPECIAL_KEYS = Set.new(%w[extras no-store no-cache max-age public private must-revalidate must-understand])
146
254
 
147
255
  def generate_weak_etag(validators)
148
256
  "W/#{generate_strong_etag(validators)}"
@@ -187,6 +295,7 @@ module ActionDispatch
187
295
  PRIVATE = "private"
188
296
  MUST_REVALIDATE = "must-revalidate"
189
297
  IMMUTABLE = "immutable"
298
+ MUST_UNDERSTAND = "must-understand"
190
299
 
191
300
  def handle_conditional_get!
192
301
  # Normally default cache control setting is handled by ETag middleware. But, if
@@ -221,6 +330,7 @@ module ActionDispatch
221
330
 
222
331
  if control[:no_store]
223
332
  options << PRIVATE if control[:private]
333
+ options << MUST_UNDERSTAND if control[:must_understand]
224
334
  options << NO_STORE
225
335
  elsif control[:no_cache]
226
336
  options << PUBLIC if control[:public]
@@ -17,9 +17,11 @@ module ActionDispatch
17
17
  # For more information about filter behavior, see
18
18
  # ActiveSupport::ParameterFilter.
19
19
  module FilterParameters
20
- ENV_MATCH = [/RAW_POST_DATA/, "rack.request.form_vars"] # :nodoc:
21
- NULL_PARAM_FILTER = ActiveSupport::ParameterFilter.new # :nodoc:
22
- NULL_ENV_FILTER = ActiveSupport::ParameterFilter.new ENV_MATCH # :nodoc:
20
+ # :stopdoc:
21
+ ENV_MATCH = [/RAW_POST_DATA/, "rack.request.form_vars"]
22
+ NULL_PARAM_FILTER = ActiveSupport::ParameterFilter.new
23
+ NULL_ENV_FILTER = ActiveSupport::ParameterFilter.new ENV_MATCH
24
+ # :startdoc:
23
25
 
24
26
  def initialize
25
27
  super
@@ -158,17 +158,7 @@ module ActionDispatch
158
158
  end
159
159
 
160
160
  def should_apply_vary_header?
161
- !params_readable?
162
- end
163
-
164
- def vary_headers # :nodoc:
165
- if use_accept_header
166
- headers = ["Accept", "X-Requested-With"]
167
- headers.insert(1, "Content-Type") if xhr? && accept.blank?
168
- headers
169
- else
170
- ["X-Requested-With"]
171
- end
161
+ !params_readable? && use_accept_header && valid_accept_header
172
162
  end
173
163
 
174
164
  private
@@ -13,6 +13,7 @@ Mime::Type.register "text/calendar", :ics
13
13
  Mime::Type.register "text/csv", :csv
14
14
  Mime::Type.register "text/vcard", :vcf
15
15
  Mime::Type.register "text/vtt", :vtt, %w(vtt)
16
+ Mime::Type.register "text/markdown", :md, [], %w(md markdown)
16
17
 
17
18
  Mime::Type.register "image/png", :png, [], %w(png)
18
19
  Mime::Type.register "image/jpeg", :jpeg, [], %w(jpg jpeg jpe pjpeg)
@@ -16,15 +16,27 @@ module ActionDispatch
16
16
  @param_depth_limit = param_depth_limit
17
17
  end
18
18
 
19
- cattr_accessor :ignore_leading_brackets
20
-
21
- LEADING_BRACKETS_COMPAT = defined?(::Rack::RELEASE) && ::Rack::RELEASE.to_s.start_with?("2.")
22
-
23
19
  cattr_accessor :default
24
20
  self.default = make_default(100)
25
21
 
26
22
  class << self
27
23
  delegate :from_query_string, :from_pairs, :from_hash, to: :default
24
+
25
+ def ignore_leading_brackets
26
+ ActionDispatch.deprecator.warn <<~MSG
27
+ ActionDispatch::ParamBuilder.ignore_leading_brackets is deprecated and have no effect and will be removed in Rails 8.2.
28
+ MSG
29
+
30
+ @ignore_leading_brackets
31
+ end
32
+
33
+ def ignore_leading_brackets=(value)
34
+ ActionDispatch.deprecator.warn <<~MSG
35
+ ActionDispatch::ParamBuilder.ignore_leading_brackets is deprecated and have no effect and will be removed in Rails 8.2.
36
+ MSG
37
+
38
+ @ignore_leading_brackets = value
39
+ end
28
40
  end
29
41
 
30
42
  def from_query_string(qs, separator: nil, encoding_template: nil)
@@ -69,30 +81,15 @@ module ActionDispatch
69
81
  # nil name, treat same as empty string (required by tests)
70
82
  k = after = ""
71
83
  elsif depth == 0
72
- if ignore_leading_brackets || (ignore_leading_brackets.nil? && LEADING_BRACKETS_COMPAT)
73
- # Rack 2 compatible behavior, ignore leading brackets
74
- if name =~ /\A[\[\]]*([^\[\]]+)\]*/
75
- k = $1
76
- after = $' || ""
77
-
78
- if !ignore_leading_brackets && (k != $& || !after.empty? && !after.start_with?("["))
79
- ActionDispatch.deprecator.warn("Skipping over leading brackets in parameter name #{name.inspect} is deprecated and will parse differently in Rails 8.1 or Rack 3.0.")
80
- end
81
- else
82
- k = name
83
- after = ""
84
- end
84
+ # Start of parsing, don't treat [] or [ at start of string specially
85
+ if start = name.index("[", 1)
86
+ # Start of parameter nesting, use part before brackets as key
87
+ k = name[0, start]
88
+ after = name[start, name.length]
85
89
  else
86
- # Start of parsing, don't treat [] or [ at start of string specially
87
- if start = name.index("[", 1)
88
- # Start of parameter nesting, use part before brackets as key
89
- k = name[0, start]
90
- after = name[start, name.length]
91
- else
92
- # Plain parameter with no nesting
93
- k = name
94
- after = ""
95
- end
90
+ # Plain parameter with no nesting
91
+ k = name
92
+ after = ""
96
93
  end
97
94
  elsif name.start_with?("[]")
98
95
  # Array nesting
@@ -111,6 +108,10 @@ module ActionDispatch
111
108
 
112
109
  return if k.empty?
113
110
 
111
+ unless k.valid_encoding?
112
+ raise InvalidParameterError, "Invalid encoding for parameter: #{k}"
113
+ end
114
+
114
115
  if depth == 0 && String === v
115
116
  # We have to wait until we've found the top part of the name,
116
117
  # because that's what the encoding template is configured with
@@ -65,14 +65,14 @@ module ActionDispatch
65
65
  alias :params :parameters
66
66
 
67
67
  def path_parameters=(parameters) # :nodoc:
68
- delete_header("action_dispatch.request.parameters")
68
+ @env.delete("action_dispatch.request.parameters")
69
69
 
70
70
  parameters = Request::Utils.set_binary_encoding(self, parameters, parameters[:controller], parameters[:action])
71
71
  # If any of the path parameters has an invalid encoding then raise since it's
72
72
  # likely to trigger errors further on.
73
73
  Request::Utils.check_param_encoding(parameters)
74
74
 
75
- set_header PARAMETERS_KEY, parameters
75
+ @env[PARAMETERS_KEY] = parameters
76
76
  rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
77
77
  raise ActionController::BadRequest.new("Invalid path parameters: #{e.message}")
78
78
  end
@@ -82,7 +82,7 @@ module ActionDispatch
82
82
  #
83
83
  # { action: "my_action", controller: "my_controller" }
84
84
  def path_parameters
85
- get_header(PARAMETERS_KEY) || set_header(PARAMETERS_KEY, {})
85
+ @env[PARAMETERS_KEY] ||= {}
86
86
  end
87
87
 
88
88
  private
@@ -186,4 +186,8 @@ module ActionDispatch # :nodoc:
186
186
  end
187
187
  end
188
188
  end
189
+
190
+ ActiveSupport.on_load(:action_dispatch_request) do
191
+ include ActionDispatch::PermissionsPolicy::Request
192
+ end
189
193
  end
@@ -6,12 +6,21 @@ require "rack"
6
6
  module ActionDispatch
7
7
  class QueryParser
8
8
  DEFAULT_SEP = /& */n
9
- COMPAT_SEP = /[&;] */n
10
9
  COMMON_SEP = { ";" => /; */n, ";," => /[;,] */n, "&" => /& */n, "&;" => /[&;] */n }
11
10
 
12
- cattr_accessor :strict_query_string_separator
11
+ def self.strict_query_string_separator
12
+ ActionDispatch.deprecator.warn <<~MSG
13
+ The `strict_query_string_separator` configuration is deprecated have no effect and will be removed in Rails 8.2.
14
+ MSG
15
+ @strict_query_string_separator
16
+ end
13
17
 
14
- SEMICOLON_COMPAT = defined?(::Rack::QueryParser::DEFAULT_SEP) && ::Rack::QueryParser::DEFAULT_SEP.to_s.include?(";")
18
+ def self.strict_query_string_separator=(value)
19
+ ActionDispatch.deprecator.warn <<~MSG
20
+ The `strict_query_string_separator` configuration is deprecated have no effect and will be removed in Rails 8.2.
21
+ MSG
22
+ @strict_query_string_separator = value
23
+ end
15
24
 
16
25
  #--
17
26
  # Note this departs from WHATWG's specified parsing algorithm by
@@ -25,13 +34,6 @@ module ActionDispatch
25
34
  splitter =
26
35
  if separator
27
36
  COMMON_SEP[separator] || /[#{separator}] */n
28
- elsif strict_query_string_separator
29
- DEFAULT_SEP
30
- elsif SEMICOLON_COMPAT && s.include?(";")
31
- if strict_query_string_separator.nil?
32
- ActionDispatch.deprecator.warn("Using semicolon as a query string separator is deprecated and will not be supported in Rails 8.1 or Rack 3.0. Use `&` instead.")
33
- end
34
- COMPAT_SEP
35
37
  else
36
38
  DEFAULT_SEP
37
39
  end
@@ -25,7 +25,6 @@ module ActionDispatch
25
25
  include ActionDispatch::Http::FilterParameters
26
26
  include ActionDispatch::Http::URL
27
27
  include ActionDispatch::ContentSecurityPolicy::Request
28
- include ActionDispatch::PermissionsPolicy::Request
29
28
  include Rack::Request::Env
30
29
 
31
30
  autoload :Session, "action_dispatch/request/session"
@@ -139,7 +138,7 @@ module ActionDispatch
139
138
 
140
139
  # Populate the HTTP method lookup cache.
141
140
  HTTP_METHODS.each { |method|
142
- HTTP_METHOD_LOOKUP[method] = method.downcase.underscore.to_sym
141
+ HTTP_METHOD_LOOKUP[method] = method.downcase.tap { |m| m.tr!("-", "_") }.to_sym
143
142
  }
144
143
 
145
144
  alias raw_request_method request_method # :nodoc:
@@ -158,11 +157,17 @@ module ActionDispatch
158
157
  #
159
158
  # request.route_uri_pattern # => "/:controller(/:action(/:id))(.:format)"
160
159
  def route_uri_pattern
161
- get_header("action_dispatch.route_uri_pattern")
160
+ unless pattern = get_header("action_dispatch.route_uri_pattern")
161
+ route = get_header("action_dispatch.route")
162
+ return if route.nil?
163
+ pattern = route.path.spec.to_s
164
+ set_header("action_dispatch.route_uri_pattern", pattern)
165
+ end
166
+ pattern
162
167
  end
163
168
 
164
- def route_uri_pattern=(pattern) # :nodoc:
165
- set_header("action_dispatch.route_uri_pattern", pattern)
169
+ def route=(route) # :nodoc:
170
+ @env["action_dispatch.route"] = route
166
171
  end
167
172
 
168
173
  def routes # :nodoc:
@@ -277,14 +277,27 @@ module ActionDispatch # :nodoc:
277
277
  # Sets the HTTP response's content MIME type. For example, in the controller you
278
278
  # could write this:
279
279
  #
280
- # response.content_type = "text/plain"
280
+ # response.content_type = "text/html"
281
+ #
282
+ # This method also accepts a symbol with the extension of the MIME type:
283
+ #
284
+ # response.content_type = :html
281
285
  #
282
286
  # If a character set has been defined for this response (see #charset=) then the
283
287
  # character set information will also be included in the content type
284
288
  # information.
285
289
  def content_type=(content_type)
286
- return unless content_type
287
- new_header_info = parse_content_type(content_type.to_s)
290
+ case content_type
291
+ when NilClass
292
+ return
293
+ when Symbol
294
+ mime_type = Mime[content_type]
295
+ raise ArgumentError, "Unknown MIME type #{content_type}" unless mime_type
296
+ new_header_info = ContentTypeHeader.new(mime_type.to_s)
297
+ else
298
+ new_header_info = parse_content_type(content_type.to_s)
299
+ end
300
+
288
301
  prev_header_info = parsed_content_type_header
289
302
  charset = new_header_info.charset || prev_header_info.charset
290
303
  charset ||= self.class.default_charset unless prev_header_info.mime_type