actionpack 4.0.13 → 4.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 (194) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +131 -1636
  3. data/README.rdoc +1 -6
  4. data/lib/abstract_controller.rb +1 -2
  5. data/lib/abstract_controller/base.rb +3 -25
  6. data/lib/abstract_controller/callbacks.rb +4 -2
  7. data/lib/abstract_controller/collector.rb +11 -1
  8. data/lib/abstract_controller/helpers.rb +18 -15
  9. data/lib/abstract_controller/rendering.rb +48 -127
  10. data/lib/action_controller.rb +1 -17
  11. data/lib/action_controller/base.rb +14 -6
  12. data/lib/action_controller/caching.rb +1 -11
  13. data/lib/action_controller/log_subscriber.rb +1 -1
  14. data/lib/action_controller/metal.rb +0 -4
  15. data/lib/action_controller/metal/flash.rb +17 -0
  16. data/lib/action_controller/metal/force_ssl.rb +1 -1
  17. data/lib/action_controller/metal/head.rb +1 -3
  18. data/lib/action_controller/metal/helpers.rb +6 -2
  19. data/lib/action_controller/metal/http_authentication.rb +7 -14
  20. data/lib/action_controller/metal/instrumentation.rb +1 -1
  21. data/lib/action_controller/metal/live.rb +74 -0
  22. data/lib/action_controller/metal/mime_responds.rb +93 -16
  23. data/lib/action_controller/metal/params_wrapper.rb +4 -11
  24. data/lib/action_controller/metal/rack_delegation.rb +1 -1
  25. data/lib/action_controller/metal/redirecting.rb +20 -20
  26. data/lib/action_controller/metal/renderers.rb +8 -5
  27. data/lib/action_controller/metal/rendering.rb +14 -11
  28. data/lib/action_controller/metal/request_forgery_protection.rb +67 -13
  29. data/lib/action_controller/metal/responder.rb +12 -2
  30. data/lib/action_controller/metal/streaming.rb +18 -20
  31. data/lib/action_controller/metal/strong_parameters.rb +22 -34
  32. data/lib/action_controller/railtie.rb +0 -1
  33. data/lib/action_controller/test_case.rb +0 -15
  34. data/lib/action_dispatch.rb +1 -0
  35. data/lib/action_dispatch/http/headers.rb +1 -3
  36. data/lib/action_dispatch/http/mime_negotiation.rb +16 -2
  37. data/lib/action_dispatch/http/mime_type.rb +4 -22
  38. data/lib/action_dispatch/http/mime_types.rb +1 -0
  39. data/lib/action_dispatch/http/parameters.rb +18 -19
  40. data/lib/action_dispatch/http/request.rb +16 -25
  41. data/lib/action_dispatch/http/response.rb +21 -8
  42. data/lib/action_dispatch/http/upload.rb +0 -13
  43. data/lib/action_dispatch/http/url.rb +10 -18
  44. data/lib/action_dispatch/journey/formatter.rb +3 -3
  45. data/lib/action_dispatch/journey/gtg/transition_table.rb +3 -5
  46. data/lib/action_dispatch/journey/parser.rb +1 -1
  47. data/lib/action_dispatch/journey/parser.y +1 -0
  48. data/lib/action_dispatch/journey/router.rb +7 -1
  49. data/lib/action_dispatch/journey/router/utils.rb +1 -1
  50. data/lib/action_dispatch/journey/visitors.rb +26 -47
  51. data/lib/action_dispatch/middleware/callbacks.rb +6 -6
  52. data/lib/action_dispatch/middleware/cookies.rb +15 -15
  53. data/lib/action_dispatch/middleware/debug_exceptions.rb +21 -13
  54. data/lib/action_dispatch/middleware/exception_wrapper.rb +1 -1
  55. data/lib/action_dispatch/middleware/flash.rb +5 -11
  56. data/lib/action_dispatch/middleware/params_parser.rb +1 -1
  57. data/lib/action_dispatch/middleware/public_exceptions.rb +1 -5
  58. data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
  59. data/lib/action_dispatch/middleware/session/cookie_store.rb +4 -3
  60. data/lib/action_dispatch/middleware/show_exceptions.rb +5 -2
  61. data/lib/action_dispatch/middleware/ssl.rb +1 -1
  62. data/lib/action_dispatch/middleware/static.rb +5 -25
  63. data/lib/action_dispatch/middleware/templates/rescues/{_request_and_response.erb → _request_and_response.html.erb} +0 -0
  64. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  65. data/lib/action_dispatch/middleware/templates/rescues/{_trace.erb → _trace.html.erb} +0 -0
  66. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +15 -0
  67. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +1 -1
  68. data/lib/action_dispatch/middleware/templates/rescues/{missing_template.erb → missing_template.html.erb} +1 -1
  69. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  70. data/lib/action_dispatch/middleware/templates/rescues/{routing_error.erb → routing_error.html.erb} +1 -1
  71. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  72. data/lib/action_dispatch/middleware/templates/rescues/{template_error.erb → template_error.html.erb} +1 -1
  73. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +8 -0
  74. data/lib/action_dispatch/middleware/templates/rescues/{unknown_action.erb → unknown_action.html.erb} +1 -1
  75. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  76. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +3 -3
  77. data/lib/action_dispatch/railtie.rb +1 -2
  78. data/lib/action_dispatch/request/session.rb +12 -0
  79. data/lib/action_dispatch/request/utils.rb +24 -0
  80. data/lib/action_dispatch/routing.rb +7 -6
  81. data/lib/action_dispatch/routing/inspector.rb +4 -4
  82. data/lib/action_dispatch/routing/mapper.rb +81 -138
  83. data/lib/action_dispatch/routing/polymorphic_routes.rb +13 -0
  84. data/lib/action_dispatch/routing/redirection.rb +34 -27
  85. data/lib/action_dispatch/routing/route_set.rb +43 -37
  86. data/lib/action_dispatch/routing/url_for.rb +3 -1
  87. data/lib/action_dispatch/testing/assertions/response.rb +8 -15
  88. data/lib/action_dispatch/testing/assertions/selector.rb +4 -4
  89. data/lib/action_dispatch/testing/integration.rb +1 -7
  90. data/lib/action_pack/version.rb +1 -1
  91. metadata +43 -167
  92. data/lib/abstract_controller/layouts.rb +0 -423
  93. data/lib/abstract_controller/view_paths.rb +0 -96
  94. data/lib/action_controller/deprecated.rb +0 -7
  95. data/lib/action_controller/deprecated/integration_test.rb +0 -5
  96. data/lib/action_controller/record_identifier.rb +0 -31
  97. data/lib/action_controller/vendor/html-scanner.rb +0 -5
  98. data/lib/action_view.rb +0 -93
  99. data/lib/action_view/base.rb +0 -205
  100. data/lib/action_view/buffers.rb +0 -49
  101. data/lib/action_view/context.rb +0 -36
  102. data/lib/action_view/dependency_tracker.rb +0 -93
  103. data/lib/action_view/digestor.rb +0 -113
  104. data/lib/action_view/flows.rb +0 -76
  105. data/lib/action_view/helpers.rb +0 -58
  106. data/lib/action_view/helpers/active_model_helper.rb +0 -49
  107. data/lib/action_view/helpers/asset_tag_helper.rb +0 -320
  108. data/lib/action_view/helpers/asset_url_helper.rb +0 -355
  109. data/lib/action_view/helpers/atom_feed_helper.rb +0 -203
  110. data/lib/action_view/helpers/cache_helper.rb +0 -196
  111. data/lib/action_view/helpers/capture_helper.rb +0 -216
  112. data/lib/action_view/helpers/controller_helper.rb +0 -25
  113. data/lib/action_view/helpers/csrf_helper.rb +0 -32
  114. data/lib/action_view/helpers/date_helper.rb +0 -1087
  115. data/lib/action_view/helpers/debug_helper.rb +0 -39
  116. data/lib/action_view/helpers/form_helper.rb +0 -1882
  117. data/lib/action_view/helpers/form_options_helper.rb +0 -838
  118. data/lib/action_view/helpers/form_tag_helper.rb +0 -785
  119. data/lib/action_view/helpers/javascript_helper.rb +0 -117
  120. data/lib/action_view/helpers/number_helper.rb +0 -451
  121. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  122. data/lib/action_view/helpers/record_tag_helper.rb +0 -106
  123. data/lib/action_view/helpers/rendering_helper.rb +0 -90
  124. data/lib/action_view/helpers/sanitize_helper.rb +0 -256
  125. data/lib/action_view/helpers/tag_helper.rb +0 -173
  126. data/lib/action_view/helpers/tags.rb +0 -39
  127. data/lib/action_view/helpers/tags/base.rb +0 -148
  128. data/lib/action_view/helpers/tags/check_box.rb +0 -64
  129. data/lib/action_view/helpers/tags/checkable.rb +0 -16
  130. data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -53
  131. data/lib/action_view/helpers/tags/collection_helpers.rb +0 -84
  132. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -36
  133. data/lib/action_view/helpers/tags/collection_select.rb +0 -28
  134. data/lib/action_view/helpers/tags/color_field.rb +0 -25
  135. data/lib/action_view/helpers/tags/date_field.rb +0 -13
  136. data/lib/action_view/helpers/tags/date_select.rb +0 -72
  137. data/lib/action_view/helpers/tags/datetime_field.rb +0 -22
  138. data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -19
  139. data/lib/action_view/helpers/tags/datetime_select.rb +0 -8
  140. data/lib/action_view/helpers/tags/email_field.rb +0 -8
  141. data/lib/action_view/helpers/tags/file_field.rb +0 -8
  142. data/lib/action_view/helpers/tags/grouped_collection_select.rb +0 -29
  143. data/lib/action_view/helpers/tags/hidden_field.rb +0 -8
  144. data/lib/action_view/helpers/tags/label.rb +0 -65
  145. data/lib/action_view/helpers/tags/month_field.rb +0 -13
  146. data/lib/action_view/helpers/tags/number_field.rb +0 -18
  147. data/lib/action_view/helpers/tags/password_field.rb +0 -12
  148. data/lib/action_view/helpers/tags/radio_button.rb +0 -31
  149. data/lib/action_view/helpers/tags/range_field.rb +0 -8
  150. data/lib/action_view/helpers/tags/search_field.rb +0 -22
  151. data/lib/action_view/helpers/tags/select.rb +0 -40
  152. data/lib/action_view/helpers/tags/tel_field.rb +0 -8
  153. data/lib/action_view/helpers/tags/text_area.rb +0 -18
  154. data/lib/action_view/helpers/tags/text_field.rb +0 -30
  155. data/lib/action_view/helpers/tags/time_field.rb +0 -13
  156. data/lib/action_view/helpers/tags/time_select.rb +0 -8
  157. data/lib/action_view/helpers/tags/time_zone_select.rb +0 -20
  158. data/lib/action_view/helpers/tags/url_field.rb +0 -8
  159. data/lib/action_view/helpers/tags/week_field.rb +0 -13
  160. data/lib/action_view/helpers/text_helper.rb +0 -448
  161. data/lib/action_view/helpers/translation_helper.rb +0 -112
  162. data/lib/action_view/helpers/url_helper.rb +0 -635
  163. data/lib/action_view/locale/en.yml +0 -56
  164. data/lib/action_view/log_subscriber.rb +0 -30
  165. data/lib/action_view/lookup_context.rb +0 -248
  166. data/lib/action_view/model_naming.rb +0 -12
  167. data/lib/action_view/path_set.rb +0 -77
  168. data/lib/action_view/railtie.rb +0 -43
  169. data/lib/action_view/record_identifier.rb +0 -84
  170. data/lib/action_view/renderer/abstract_renderer.rb +0 -47
  171. data/lib/action_view/renderer/partial_renderer.rb +0 -500
  172. data/lib/action_view/renderer/renderer.rb +0 -50
  173. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -103
  174. data/lib/action_view/renderer/template_renderer.rb +0 -96
  175. data/lib/action_view/routing_url_for.rb +0 -107
  176. data/lib/action_view/tasks/dependencies.rake +0 -17
  177. data/lib/action_view/template.rb +0 -339
  178. data/lib/action_view/template/error.rb +0 -138
  179. data/lib/action_view/template/handlers.rb +0 -53
  180. data/lib/action_view/template/handlers/builder.rb +0 -26
  181. data/lib/action_view/template/handlers/erb.rb +0 -146
  182. data/lib/action_view/template/handlers/raw.rb +0 -11
  183. data/lib/action_view/template/resolver.rb +0 -340
  184. data/lib/action_view/template/text.rb +0 -34
  185. data/lib/action_view/template/types.rb +0 -57
  186. data/lib/action_view/test_case.rb +0 -270
  187. data/lib/action_view/testing/resolvers.rb +0 -50
  188. data/lib/action_view/vendor/html-scanner.rb +0 -20
  189. data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
  190. data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
  191. data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
  192. data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
  193. data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
  194. data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
@@ -3,7 +3,7 @@ require 'action_controller/metal/exceptions'
3
3
  module ActionDispatch
4
4
  module Journey
5
5
  # The Formatter class is used for formatting URLs. For example, parameters
6
- # passed to +url_for+ in rails will eventually call Formatter#generate.
6
+ # passed to +url_for+ in Rails will eventually call Formatter#generate.
7
7
  class Formatter # :nodoc:
8
8
  attr_reader :routes
9
9
 
@@ -33,8 +33,8 @@ module ActionDispatch
33
33
  return [route.format(parameterized_parts), params]
34
34
  end
35
35
 
36
- message = "No route matches #{Hash[constraints.sort].inspect}"
37
- message << " missing required keys: #{missing_keys.sort.inspect}" unless missing_keys.empty?
36
+ message = "No route matches #{constraints.inspect}"
37
+ message << " missing required keys: #{missing_keys.inspect}" if name
38
38
 
39
39
  raise ActionController::UrlGenerationError, message
40
40
  end
@@ -43,9 +43,7 @@ module ActionDispatch
43
43
  move_string(t, a).concat(move_regexp(t, a))
44
44
  end
45
45
 
46
- def to_json
47
- require 'json'
48
-
46
+ def as_json(options = nil)
49
47
  simple_regexp = Hash.new { |h,k| h[k] = {} }
50
48
 
51
49
  @regexp_states.each do |from, hash|
@@ -54,11 +52,11 @@ module ActionDispatch
54
52
  end
55
53
  end
56
54
 
57
- JSON.dump({
55
+ {
58
56
  regexp_states: simple_regexp,
59
57
  string_states: @string_states,
60
58
  accepting: @accepting
61
- })
59
+ }
62
60
  end
63
61
 
64
62
  def to_svg
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
3
  # This file is automatically generated by Racc 1.4.9
4
- # from Racc grammer file "".
4
+ # from Racc grammar file "".
5
5
  #
6
6
 
7
7
  require 'racc/parser.rb'
@@ -36,6 +36,7 @@ rule
36
36
  ;
37
37
  literal
38
38
  : LITERAL { result = Literal.new(val.first) }
39
+ ;
39
40
  dot
40
41
  : DOT { result = Dot.new(val.first) }
41
42
  ;
@@ -54,7 +54,7 @@ module ActionDispatch
54
54
  end
55
55
 
56
56
  def call(env)
57
- env['PATH_INFO'] = Utils.normalize_path(env['PATH_INFO'])
57
+ env['PATH_INFO'] = normalize_path(env['PATH_INFO'])
58
58
 
59
59
  find_routes(env).each do |match, parameters, route|
60
60
  script_name, path_info, set_params = env.values_at('SCRIPT_NAME',
@@ -103,6 +103,12 @@ module ActionDispatch
103
103
 
104
104
  private
105
105
 
106
+ def normalize_path(path)
107
+ path = "/#{path}"
108
+ path.squeeze!('/')
109
+ path
110
+ end
111
+
106
112
  def partitioned_routes
107
113
  routes.partitioned_routes
108
114
  end
@@ -38,7 +38,7 @@ module ActionDispatch
38
38
  UNSAFE_FRAGMENT = Regexp.new("[^#{safe_fragment}]", false).freeze
39
39
  end
40
40
 
41
- Parser = URI.const_defined?(:Parser) ? URI::Parser.new : URI
41
+ Parser = URI::Parser.new
42
42
 
43
43
  def self.escape_path(path)
44
44
  Parser.escape(path.to_s, UriEscape::UNSAFE_SEGMENT)
@@ -77,74 +77,53 @@ module ActionDispatch
77
77
  end
78
78
  end
79
79
 
80
- class OptimizedPath < Visitor # :nodoc:
81
- def accept(node)
82
- Array(visit(node))
83
- end
84
-
80
+ class OptimizedPath < String # :nodoc:
85
81
  private
86
82
 
87
- def visit_CAT(node)
88
- [visit(node.left), visit(node.right)].flatten
89
- end
90
-
91
- def visit_SYMBOL(node)
92
- node.left[1..-1].to_sym
93
- end
94
-
95
- def visit_STAR(node)
96
- visit(node.left)
97
- end
98
-
99
- def visit_GROUP(node)
100
- []
101
- end
102
-
103
- %w{ LITERAL SLASH DOT }.each do |t|
104
- class_eval %{ def visit_#{t}(n); n.left; end }, __FILE__, __LINE__
105
- end
83
+ def visit_GROUP(node)
84
+ ""
85
+ end
106
86
  end
107
87
 
108
88
  # Used for formatting urls (url_for)
109
89
  class Formatter < Visitor # :nodoc:
110
- attr_reader :options, :consumed
90
+ attr_reader :options
111
91
 
112
92
  def initialize(options)
113
93
  @options = options
114
- @consumed = {}
115
94
  end
116
95
 
117
96
  private
118
97
 
119
- def visit_GROUP(node)
120
- if consumed == options
121
- nil
122
- else
123
- route = visit(node.left)
124
- route.include?("\0") ? nil : route
98
+ def visit(node, optional = false)
99
+ case node.type
100
+ when :LITERAL, :SLASH, :DOT
101
+ node.left
102
+ when :STAR
103
+ visit(node.left)
104
+ when :GROUP
105
+ visit(node.left, true)
106
+ when :CAT
107
+ visit_CAT(node, optional)
108
+ when :SYMBOL
109
+ visit_SYMBOL(node)
125
110
  end
126
111
  end
127
112
 
128
- def terminal(node)
129
- node.left
130
- end
113
+ def visit_CAT(node, optional)
114
+ left = visit(node.left, optional)
115
+ right = visit(node.right, optional)
131
116
 
132
- def binary(node)
133
- [visit(node.left), visit(node.right)].join
134
- end
135
-
136
- def nary(node)
137
- node.children.map { |c| visit(c) }.join
117
+ if optional && !(right && left)
118
+ ""
119
+ else
120
+ [left, right].join
121
+ end
138
122
  end
139
123
 
140
124
  def visit_SYMBOL(node)
141
- key = node.to_sym
142
-
143
- if value = options[key]
144
- consumed[key] = value
125
+ if value = options[node.to_sym]
145
126
  Router::Utils.escape_path(value)
146
- else
147
- "\0"
148
127
  end
149
128
  end
150
129
  end
@@ -8,14 +8,14 @@ module ActionDispatch
8
8
 
9
9
  class << self
10
10
  delegate :to_prepare, :to_cleanup, :to => "ActionDispatch::Reloader"
11
- end
12
11
 
13
- def self.before(*args, &block)
14
- set_callback(:call, :before, *args, &block)
15
- end
12
+ def before(*args, &block)
13
+ set_callback(:call, :before, *args, &block)
14
+ end
16
15
 
17
- def self.after(*args, &block)
18
- set_callback(:call, :after, *args, &block)
16
+ def after(*args, &block)
17
+ set_callback(:call, :after, *args, &block)
18
+ end
19
19
  end
20
20
 
21
21
  def initialize(app)
@@ -23,14 +23,14 @@ module ActionDispatch
23
23
  # # This cookie will be deleted when the user's browser is closed.
24
24
  # cookies[:user_name] = "david"
25
25
  #
26
- # # Cookie values are String based. Other data types need to be serialized.
27
- # cookies[:lat_lon] = JSON.generate([47.68, -122.37])
26
+ # # Assign an array of values to a cookie.
27
+ # cookies[:lat_lon] = [47.68, -122.37]
28
28
  #
29
29
  # # Sets a cookie that expires in 1 hour.
30
30
  # cookies[:login] = { value: "XJ-122", expires: 1.hour.from_now }
31
31
  #
32
32
  # # Sets a signed cookie, which prevents users from tampering with its value.
33
- # # The cookie is signed by your app's <tt>config.secret_key_base</tt> value.
33
+ # # The cookie is signed by your app's <tt>secrets.secret_key_base</tt> value.
34
34
  # # It can be read using the signed method <tt>cookies.signed[:name]</tt>
35
35
  # cookies.signed[:user_id] = current_user.id
36
36
  #
@@ -42,10 +42,10 @@ module ActionDispatch
42
42
  #
43
43
  # Examples of reading:
44
44
  #
45
- # cookies[:user_name] # => "david"
46
- # cookies.size # => 2
47
- # JSON.parse(cookies[:lat_lon]) # => [47.68, -122.37]
48
- # cookies.signed[:login] # => "XJ-122"
45
+ # cookies[:user_name] # => "david"
46
+ # cookies.size # => 2
47
+ # cookies[:lat_lon] # => [47.68, -122.37]
48
+ # cookies.signed[:login] # => "XJ-122"
49
49
  #
50
50
  # Example for deleting:
51
51
  #
@@ -63,7 +63,7 @@ module ActionDispatch
63
63
  #
64
64
  # The option symbols for setting cookies are:
65
65
  #
66
- # * <tt>:value</tt> - The cookie's value.
66
+ # * <tt>:value</tt> - The cookie's value or list of values (as an array).
67
67
  # * <tt>:path</tt> - The path for which this cookie applies. Defaults to the root
68
68
  # of the application.
69
69
  # * <tt>:domain</tt> - The domain for which this cookie applies so you can
@@ -117,10 +117,10 @@ module ActionDispatch
117
117
  # the cookie again. This is useful for creating cookies with values that the user is not supposed to change. If a signed
118
118
  # cookie was tampered with by the user (or a 3rd party), nil will be returned.
119
119
  #
120
- # If +config.secret_key_base+ and +config.secret_token+ (deprecated) are both set,
120
+ # If +secrets.secret_key_base+ and +config.secret_token+ (deprecated) are both set,
121
121
  # legacy cookies signed with the old key generator will be transparently upgraded.
122
122
  #
123
- # This jar requires that you set a suitable secret for the verification on your app's +config.secret_key_base+.
123
+ # This jar requires that you set a suitable secret for the verification on your app's +secrets.secret_key_base+.
124
124
  #
125
125
  # Example:
126
126
  #
@@ -140,10 +140,10 @@ module ActionDispatch
140
140
  # Returns a jar that'll automatically encrypt cookie values before sending them to the client and will decrypt them for read.
141
141
  # If the cookie was tampered with by the user (or a 3rd party), nil will be returned.
142
142
  #
143
- # If +config.secret_key_base+ and +config.secret_token+ (deprecated) are both set,
143
+ # If +secrets.secret_key_base+ and +config.secret_token+ (deprecated) are both set,
144
144
  # legacy cookies signed with the old key generator will be transparently upgraded.
145
145
  #
146
- # This jar requires that you set a suitable secret for the verification on your app's +config.secret_key_base+.
146
+ # This jar requires that you set a suitable secret for the verification on your app's +secrets.secret_key_base+.
147
147
  #
148
148
  # Example:
149
149
  #
@@ -409,7 +409,7 @@ module ActionDispatch
409
409
  end
410
410
 
411
411
  # UpgradeLegacySignedCookieJar is used instead of SignedCookieJar if
412
- # config.secret_token and config.secret_key_base are both set. It reads
412
+ # config.secret_token and secrets.secret_key_base are both set. It reads
413
413
  # legacy cookies signed with the old dummy key generator and re-saves
414
414
  # them using the new key generator to provide a smooth upgrade path.
415
415
  class UpgradeLegacySignedCookieJar < SignedCookieJar #:nodoc:
@@ -427,7 +427,7 @@ module ActionDispatch
427
427
 
428
428
  def initialize(parent_jar, key_generator, options = {})
429
429
  if ActiveSupport::LegacyKeyGenerator === key_generator
430
- raise "You didn't set config.secret_key_base, which is required for this cookie jar. " +
430
+ raise "You didn't set secrets.secret_key_base, which is required for this cookie jar. " +
431
431
  "Read the upgrade documentation to learn more about this new config option."
432
432
  end
433
433
 
@@ -465,7 +465,7 @@ module ActionDispatch
465
465
  end
466
466
 
467
467
  # UpgradeLegacyEncryptedCookieJar is used by ActionDispatch::Session::CookieStore
468
- # instead of EncryptedCookieJar if config.secret_token and config.secret_key_base
468
+ # instead of EncryptedCookieJar if config.secret_token and secrets.secret_key_base
469
469
  # are both set. It reads legacy cookies signed with the old dummy key generator and
470
470
  # encrypts and re-saves them using the new key generator to provide a smooth upgrade path.
471
471
  class UpgradeLegacyEncryptedCookieJar < EncryptedCookieJar #:nodoc:
@@ -34,27 +34,35 @@ module ActionDispatch
34
34
  log_error(env, wrapper)
35
35
 
36
36
  if env['action_dispatch.show_detailed_exceptions']
37
+ request = Request.new(env)
37
38
  template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
38
- :request => Request.new(env),
39
- :exception => wrapper.exception,
40
- :application_trace => wrapper.application_trace,
41
- :framework_trace => wrapper.framework_trace,
42
- :full_trace => wrapper.full_trace,
43
- :routes_inspector => routes_inspector(exception),
44
- :source_extract => wrapper.source_extract,
45
- :line_number => wrapper.line_number,
46
- :file => wrapper.file
39
+ request: request,
40
+ exception: wrapper.exception,
41
+ application_trace: wrapper.application_trace,
42
+ framework_trace: wrapper.framework_trace,
43
+ full_trace: wrapper.full_trace,
44
+ routes_inspector: routes_inspector(exception),
45
+ source_extract: wrapper.source_extract,
46
+ line_number: wrapper.line_number,
47
+ file: wrapper.file
47
48
  )
48
49
  file = "rescues/#{wrapper.rescue_template}"
49
- body = template.render(:template => file, :layout => 'rescues/layout')
50
- render(wrapper.status_code, body)
50
+
51
+ if request.xhr?
52
+ body = template.render(template: file, layout: false, formats: [:text])
53
+ format = "text/plain"
54
+ else
55
+ body = template.render(template: file, layout: 'rescues/layout')
56
+ format = "text/html"
57
+ end
58
+ render(wrapper.status_code, body, format)
51
59
  else
52
60
  raise exception
53
61
  end
54
62
  end
55
63
 
56
- def render(status, body)
57
- [status, {'Content-Type' => "text/html; charset=#{Response.default_charset}", 'Content-Length' => body.bytesize.to_s}, [body]]
64
+ def render(status, body, format)
65
+ [status, {'Content-Type' => "#{format}; charset=#{Response.default_charset}", 'Content-Length' => body.bytesize.to_s}, [body]]
58
66
  end
59
67
 
60
68
  def log_error(env, wrapper)
@@ -1,5 +1,5 @@
1
1
  require 'action_controller/metal/exceptions'
2
- require 'active_support/core_ext/class/attribute_accessors'
2
+ require 'active_support/core_ext/module/attribute_accessors'
3
3
 
4
4
  module ActionDispatch
5
5
  class ExceptionWrapper
@@ -125,7 +125,7 @@ module ActionDispatch
125
125
  end
126
126
 
127
127
  def key?(name)
128
- @flashes.key? name.to_s
128
+ @flashes.key? name
129
129
  end
130
130
 
131
131
  def delete(key)
@@ -243,19 +243,13 @@ module ActionDispatch
243
243
  session = Request::Session.find(env) || {}
244
244
  flash_hash = env[KEY]
245
245
 
246
- if flash_hash
247
- if !flash_hash.empty? || session.key?('flash')
248
- session["flash"] = flash_hash.to_session_value
249
- new_hash = flash_hash.dup
250
- else
251
- new_hash = flash_hash
252
- end
253
-
254
- env[KEY] = new_hash
246
+ if flash_hash && (flash_hash.present? || session.key?('flash'))
247
+ session["flash"] = flash_hash.to_session_value
248
+ env[KEY] = flash_hash.dup
255
249
  end
256
250
 
257
251
  if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?)
258
- session.key?('flash') && session['flash'].nil?
252
+ session.key?('flash') && session['flash'].nil?
259
253
  session.delete('flash')
260
254
  end
261
255
  end
@@ -43,7 +43,7 @@ module ActionDispatch
43
43
  when :json
44
44
  data = ActiveSupport::JSON.decode(request.raw_post)
45
45
  data = {:_json => data} unless data.is_a?(Hash)
46
- request.deep_munge(data).with_indifferent_access
46
+ Request::Utils.deep_munge(data).with_indifferent_access
47
47
  else
48
48
  false
49
49
  end
@@ -9,12 +9,8 @@ module ActionDispatch
9
9
  def call(env)
10
10
  status = env["PATH_INFO"][1..-1]
11
11
  request = ActionDispatch::Request.new(env)
12
+ content_type = request.formats.first
12
13
  body = { :status => status, :error => Rack::Utils::HTTP_STATUS_CODES.fetch(status.to_i, Rack::Utils::HTTP_STATUS_CODES[500]) }
13
- content_type = begin
14
- request.formats.first
15
- rescue ActionController::BadRequest
16
- Mime::HTML
17
- end
18
14
 
19
15
  render(status, content_type, body)
20
16
  end
@@ -16,9 +16,9 @@ module ActionDispatch
16
16
 
17
17
  # Get a session from the cache.
18
18
  def get_session(env, sid)
19
- unless sid and session = @cache.read(cache_key(sid))
20
- sid, session = generate_sid, {}
21
- end
19
+ sid ||= generate_sid
20
+ session = @cache.read(cache_key(sid))
21
+ session ||= {}
22
22
  [sid, session]
23
23
  end
24
24
 
@@ -31,9 +31,10 @@ module ActionDispatch
31
31
  #
32
32
  # Myapp::Application.config.session_store :cookie_store, key: '_your_app_session'
33
33
  #
34
- # Configure your secret key in config/initializers/secret_token.rb:
34
+ # Configure your secret key in config/secrets.yml:
35
35
  #
36
- # Myapp::Application.config.secret_key_base 'secret key'
36
+ # development:
37
+ # secret_key_base: 'secret key'
37
38
  #
38
39
  # To generate a secret key for an existing application, run `rake secret`.
39
40
  #
@@ -50,7 +51,7 @@ module ActionDispatch
50
51
  # decode signed cookies generated by your app in external applications or
51
52
  # Javascript before upgrading.
52
53
  #
53
- # Note that changing the secret key will invalidate all existing sessions!
54
+ # Note that changing digest or secret invalidates all existing sessions!
54
55
  class CookieStore < Rack::Session::Abstract::ID
55
56
  include Compatibility
56
57
  include StaleSessionCheck