actionpack 7.2.3.1 → 8.1.4.1

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 (109) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +606 -120
  3. data/lib/abstract_controller/asset_paths.rb +4 -2
  4. data/lib/abstract_controller/base.rb +11 -5
  5. data/lib/abstract_controller/caching.rb +6 -3
  6. data/lib/abstract_controller/callbacks.rb +6 -0
  7. data/lib/abstract_controller/logger.rb +2 -1
  8. data/lib/abstract_controller/rendering.rb +0 -1
  9. data/lib/action_controller/api.rb +1 -0
  10. data/lib/action_controller/base.rb +3 -2
  11. data/lib/action_controller/caching.rb +1 -2
  12. data/lib/action_controller/form_builder.rb +4 -4
  13. data/lib/action_controller/log_subscriber.rb +22 -3
  14. data/lib/action_controller/metal/allow_browser.rb +12 -2
  15. data/lib/action_controller/metal/conditional_get.rb +30 -1
  16. data/lib/action_controller/metal/data_streaming.rb +5 -5
  17. data/lib/action_controller/metal/exceptions.rb +5 -0
  18. data/lib/action_controller/metal/flash.rb +1 -4
  19. data/lib/action_controller/metal/head.rb +3 -1
  20. data/lib/action_controller/metal/http_authentication.rb +1 -1
  21. data/lib/action_controller/metal/instrumentation.rb +1 -2
  22. data/lib/action_controller/metal/live.rb +83 -31
  23. data/lib/action_controller/metal/permissions_policy.rb +9 -0
  24. data/lib/action_controller/metal/rate_limiting.rb +39 -9
  25. data/lib/action_controller/metal/redirecting.rb +107 -14
  26. data/lib/action_controller/metal/renderers.rb +29 -9
  27. data/lib/action_controller/metal/rendering.rb +16 -3
  28. data/lib/action_controller/metal/request_forgery_protection.rb +18 -10
  29. data/lib/action_controller/metal/rescue.rb +9 -0
  30. data/lib/action_controller/metal/streaming.rb +5 -84
  31. data/lib/action_controller/metal/strong_parameters.rb +294 -98
  32. data/lib/action_controller/railtie.rb +35 -15
  33. data/lib/action_controller/structured_event_subscriber.rb +116 -0
  34. data/lib/action_controller/test_case.rb +12 -2
  35. data/lib/action_dispatch/http/cache.rb +143 -12
  36. data/lib/action_dispatch/http/content_security_policy.rb +14 -1
  37. data/lib/action_dispatch/http/filter_parameters.rb +5 -3
  38. data/lib/action_dispatch/http/mime_negotiation.rb +66 -2
  39. data/lib/action_dispatch/http/mime_types.rb +1 -0
  40. data/lib/action_dispatch/http/param_builder.rb +187 -0
  41. data/lib/action_dispatch/http/param_error.rb +26 -0
  42. data/lib/action_dispatch/http/parameters.rb +3 -3
  43. data/lib/action_dispatch/http/permissions_policy.rb +8 -1
  44. data/lib/action_dispatch/http/query_parser.rb +55 -0
  45. data/lib/action_dispatch/http/request.rb +70 -21
  46. data/lib/action_dispatch/http/response.rb +52 -17
  47. data/lib/action_dispatch/http/url.rb +112 -16
  48. data/lib/action_dispatch/journey/formatter.rb +5 -0
  49. data/lib/action_dispatch/journey/gtg/simulator.rb +33 -12
  50. data/lib/action_dispatch/journey/gtg/transition_table.rb +33 -41
  51. data/lib/action_dispatch/journey/nodes/node.rb +2 -1
  52. data/lib/action_dispatch/journey/parser.rb +99 -196
  53. data/lib/action_dispatch/journey/route.rb +45 -31
  54. data/lib/action_dispatch/journey/router/utils.rb +9 -15
  55. data/lib/action_dispatch/journey/router.rb +59 -81
  56. data/lib/action_dispatch/journey/routes.rb +7 -0
  57. data/lib/action_dispatch/journey/scanner.rb +44 -42
  58. data/lib/action_dispatch/journey/visitors.rb +55 -23
  59. data/lib/action_dispatch/journey/visualizer/fsm.js +4 -6
  60. data/lib/action_dispatch/log_subscriber.rb +7 -3
  61. data/lib/action_dispatch/middleware/cookies.rb +24 -5
  62. data/lib/action_dispatch/middleware/debug_exceptions.rb +24 -5
  63. data/lib/action_dispatch/middleware/debug_view.rb +11 -5
  64. data/lib/action_dispatch/middleware/exception_wrapper.rb +12 -12
  65. data/lib/action_dispatch/middleware/executor.rb +12 -2
  66. data/lib/action_dispatch/middleware/host_authorization.rb +3 -2
  67. data/lib/action_dispatch/middleware/public_exceptions.rb +1 -5
  68. data/lib/action_dispatch/middleware/remote_ip.rb +61 -24
  69. data/lib/action_dispatch/middleware/request_id.rb +2 -1
  70. data/lib/action_dispatch/middleware/session/abstract_store.rb +5 -0
  71. data/lib/action_dispatch/middleware/session/cache_store.rb +44 -4
  72. data/lib/action_dispatch/middleware/session/cookie_store.rb +0 -3
  73. data/lib/action_dispatch/middleware/ssl.rb +13 -3
  74. data/lib/action_dispatch/middleware/templates/rescues/_copy_button.html.erb +1 -0
  75. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +3 -5
  76. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +9 -5
  77. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +1 -0
  78. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +1 -0
  79. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +4 -0
  80. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +3 -0
  81. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +50 -0
  82. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +1 -0
  83. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -0
  84. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +7 -8
  85. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +1 -1
  86. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -0
  87. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -0
  88. data/lib/action_dispatch/railtie.rb +21 -0
  89. data/lib/action_dispatch/request/session.rb +1 -0
  90. data/lib/action_dispatch/request/utils.rb +9 -3
  91. data/lib/action_dispatch/routing/inspector.rb +80 -57
  92. data/lib/action_dispatch/routing/mapper.rb +404 -223
  93. data/lib/action_dispatch/routing/polymorphic_routes.rb +2 -2
  94. data/lib/action_dispatch/routing/redirection.rb +10 -7
  95. data/lib/action_dispatch/routing/route_set.rb +21 -12
  96. data/lib/action_dispatch/routing/routes_proxy.rb +1 -0
  97. data/lib/action_dispatch/structured_event_subscriber.rb +20 -0
  98. data/lib/action_dispatch/system_test_case.rb +3 -3
  99. data/lib/action_dispatch/system_testing/browser.rb +15 -22
  100. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +2 -2
  101. data/lib/action_dispatch/testing/assertions/response.rb +26 -2
  102. data/lib/action_dispatch/testing/assertions/routing.rb +27 -15
  103. data/lib/action_dispatch/testing/integration.rb +18 -7
  104. data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +1 -1
  105. data/lib/action_dispatch.rb +14 -4
  106. data/lib/action_pack/gem_version.rb +3 -3
  107. metadata +18 -48
  108. data/lib/action_dispatch/journey/parser.y +0 -50
  109. data/lib/action_dispatch/journey/parser_extras.rb +0 -33
@@ -64,6 +64,14 @@ module ActionDispatch
64
64
  def engine?
65
65
  app.engine?
66
66
  end
67
+
68
+ def to_h
69
+ { name: name,
70
+ verb: verb,
71
+ path: path,
72
+ reqs: reqs,
73
+ source_location: source_location }
74
+ end
67
75
  end
68
76
 
69
77
  ##
@@ -72,36 +80,57 @@ module ActionDispatch
72
80
  # not use this class.
73
81
  class RoutesInspector # :nodoc:
74
82
  def initialize(routes)
75
- @engines = {}
76
- @routes = routes
83
+ @routes = wrap_routes(routes)
84
+ @engines = load_engines_routes
77
85
  end
78
86
 
79
87
  def format(formatter, filter = {})
80
- routes_to_display = filter_routes(normalize_filter(filter))
81
- routes = collect_routes(routes_to_display)
82
- if routes.none?
83
- formatter.no_routes(collect_routes(@routes), filter)
84
- return formatter.result
85
- end
88
+ all_routes = { nil => @routes }.merge(@engines)
86
89
 
87
- formatter.header routes
88
- formatter.section routes
89
-
90
- @engines.each do |name, engine_routes|
91
- formatter.section_title "Routes for #{name}"
92
- formatter.section engine_routes
90
+ all_routes.each do |engine_name, routes|
91
+ format_routes(formatter, filter, engine_name, routes)
93
92
  end
94
93
 
95
94
  formatter.result
96
95
  end
97
96
 
98
97
  private
98
+ def format_routes(formatter, filter, engine_name, routes)
99
+ routes = filter_routes(routes, normalize_filter(filter)).map(&:to_h)
100
+
101
+ formatter.section_title "Routes for #{engine_name || "application"}" if @engines.any?
102
+ if routes.any?
103
+ formatter.header routes
104
+ formatter.section routes
105
+ else
106
+ formatter.no_routes engine_name, routes, filter
107
+ end
108
+ formatter.footer routes
109
+ end
110
+
111
+ def wrap_routes(routes)
112
+ routes.routes.map { |route| RouteWrapper.new(route) }.reject(&:internal?)
113
+ end
114
+
115
+ def load_engines_routes
116
+ engine_routes = @routes.select(&:engine?)
117
+
118
+ engines = engine_routes.to_h do |engine_route|
119
+ engine_app_routes = engine_route.rack_app.routes
120
+ engine_app_routes = engine_app_routes.routes if engine_app_routes.is_a?(ActionDispatch::Routing::RouteSet)
121
+
122
+ [engine_route.endpoint, wrap_routes(engine_app_routes)]
123
+ end
124
+
125
+ engines
126
+ end
127
+
99
128
  def normalize_filter(filter)
100
129
  if filter[:controller]
101
130
  { controller: /#{filter[:controller].underscore.sub(/_?controller\z/, "")}/ }
102
131
  elsif filter[:grep]
103
132
  grep_pattern = Regexp.new(filter[:grep])
104
- path = RFC2396_PARSER.escape(filter[:grep])
133
+ path = URI::RFC2396_PARSER.escape(filter[:grep])
105
134
  normalized_path = ("/" + path).squeeze("/")
106
135
 
107
136
  {
@@ -115,39 +144,13 @@ module ActionDispatch
115
144
  end
116
145
  end
117
146
 
118
- def filter_routes(filter)
147
+ def filter_routes(routes, filter)
119
148
  if filter
120
- @routes.select do |route|
121
- route_wrapper = RouteWrapper.new(route)
122
- filter.any? { |filter_type, value| route_wrapper.matches_filter?(filter_type, value) }
149
+ routes.select do |route|
150
+ filter.any? { |filter_type, value| route.matches_filter?(filter_type, value) }
123
151
  end
124
152
  else
125
- @routes
126
- end
127
- end
128
-
129
- def collect_routes(routes)
130
- routes.collect do |route|
131
- RouteWrapper.new(route)
132
- end.reject(&:internal?).collect do |route|
133
- collect_engine_routes(route)
134
-
135
- { name: route.name,
136
- verb: route.verb,
137
- path: route.path,
138
- reqs: route.reqs,
139
- source_location: route.source_location }
140
- end
141
- end
142
-
143
- def collect_engine_routes(route)
144
- name = route.endpoint
145
- return unless route.engine?
146
- return if @engines[name]
147
-
148
- routes = route.rack_app.routes
149
- if routes.is_a?(ActionDispatch::Routing::RouteSet)
150
- @engines[name] = collect_routes(routes.routes)
153
+ routes
151
154
  end
152
155
  end
153
156
  end
@@ -171,27 +174,36 @@ module ActionDispatch
171
174
  def header(routes)
172
175
  end
173
176
 
174
- def no_routes(routes, filter)
175
- @buffer <<
176
- if routes.none?
177
- <<~MESSAGE
178
- You don't have any routes defined!
177
+ def footer(routes)
178
+ end
179
179
 
180
- Please add some routes in config/routes.rb.
181
- MESSAGE
182
- elsif filter.key?(:controller)
180
+ def no_routes(engine, routes, filter)
181
+ @buffer <<
182
+ if filter.key?(:controller)
183
183
  "No routes were found for this controller."
184
184
  elsif filter.key?(:grep)
185
185
  "No routes were found for this grep pattern."
186
+ elsif routes.none?
187
+ if engine
188
+ "No routes defined."
189
+ else
190
+ <<~MESSAGE
191
+ You don't have any routes defined!
192
+
193
+ Please add some routes in config/routes.rb.
194
+ MESSAGE
195
+ end
186
196
  end
187
197
 
188
- @buffer << "For more information about routes, see the Rails guide: https://guides.rubyonrails.org/routing.html."
198
+ unless engine
199
+ @buffer << "For more information about routes, see the Rails guide: https://guides.rubyonrails.org/routing.html."
200
+ end
189
201
  end
190
202
  end
191
203
 
192
204
  class Sheet < Base
193
205
  def section_title(title)
194
- @buffer << "\n#{title}:"
206
+ @buffer << "#{title}:"
195
207
  end
196
208
 
197
209
  def section(routes)
@@ -202,6 +214,10 @@ module ActionDispatch
202
214
  @buffer << draw_header(routes)
203
215
  end
204
216
 
217
+ def footer(routes)
218
+ @buffer << ""
219
+ end
220
+
205
221
  private
206
222
  def draw_section(routes)
207
223
  header_lengths = ["Prefix", "Verb", "URI Pattern"].map(&:length)
@@ -232,13 +248,17 @@ module ActionDispatch
232
248
  end
233
249
 
234
250
  def section_title(title)
235
- @buffer << "\n#{"[ #{title} ]"}"
251
+ @buffer << "#{"[ #{title} ]"}"
236
252
  end
237
253
 
238
254
  def section(routes)
239
255
  @buffer << draw_expanded_section(routes)
240
256
  end
241
257
 
258
+ def footer(routes)
259
+ @buffer << ""
260
+ end
261
+
242
262
  private
243
263
  def draw_expanded_section(routes)
244
264
  routes.map.each_with_index do |r, i|
@@ -269,7 +289,7 @@ module ActionDispatch
269
289
  super
270
290
  end
271
291
 
272
- def no_routes(routes, filter)
292
+ def no_routes(engine, routes, filter)
273
293
  @buffer <<
274
294
  if filter.none?
275
295
  "No unused routes found."
@@ -300,6 +320,9 @@ module ActionDispatch
300
320
  def header(routes)
301
321
  end
302
322
 
323
+ def footer(routes)
324
+ end
325
+
303
326
  def no_routes(*)
304
327
  @buffer << <<~MESSAGE
305
328
  <p>You don't have any routes defined!</p>