actionview 7.0.1 → 7.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +281 -202
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +3 -3
  5. data/app/assets/javascripts/rails-ujs.esm.js +693 -0
  6. data/app/assets/javascripts/rails-ujs.js +630 -0
  7. data/lib/action_view/base.rb +33 -12
  8. data/lib/action_view/buffers.rb +106 -8
  9. data/lib/action_view/cache_expiry.rb +40 -43
  10. data/lib/action_view/context.rb +1 -1
  11. data/lib/action_view/deprecator.rb +7 -0
  12. data/lib/action_view/digestor.rb +1 -1
  13. data/lib/action_view/gem_version.rb +2 -2
  14. data/lib/action_view/helpers/active_model_helper.rb +1 -1
  15. data/lib/action_view/helpers/asset_tag_helper.rb +133 -48
  16. data/lib/action_view/helpers/asset_url_helper.rb +13 -12
  17. data/lib/action_view/helpers/atom_feed_helper.rb +5 -5
  18. data/lib/action_view/helpers/cache_helper.rb +3 -9
  19. data/lib/action_view/helpers/capture_helper.rb +26 -12
  20. data/lib/action_view/helpers/content_exfiltration_prevention_helper.rb +70 -0
  21. data/lib/action_view/helpers/controller_helper.rb +6 -0
  22. data/lib/action_view/helpers/csp_helper.rb +2 -2
  23. data/lib/action_view/helpers/csrf_helper.rb +3 -3
  24. data/lib/action_view/helpers/date_helper.rb +76 -64
  25. data/lib/action_view/helpers/debug_helper.rb +3 -3
  26. data/lib/action_view/helpers/form_helper.rb +62 -31
  27. data/lib/action_view/helpers/form_options_helper.rb +6 -3
  28. data/lib/action_view/helpers/form_tag_helper.rb +88 -44
  29. data/lib/action_view/helpers/javascript_helper.rb +1 -0
  30. data/lib/action_view/helpers/number_helper.rb +15 -13
  31. data/lib/action_view/helpers/output_safety_helper.rb +4 -4
  32. data/lib/action_view/helpers/rendering_helper.rb +5 -6
  33. data/lib/action_view/helpers/sanitize_helper.rb +34 -15
  34. data/lib/action_view/helpers/tag_helper.rb +27 -16
  35. data/lib/action_view/helpers/tags/base.rb +11 -52
  36. data/lib/action_view/helpers/tags/collection_check_boxes.rb +1 -0
  37. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +1 -0
  38. data/lib/action_view/helpers/tags/collection_select.rb +3 -0
  39. data/lib/action_view/helpers/tags/date_field.rb +1 -1
  40. data/lib/action_view/helpers/tags/date_select.rb +2 -0
  41. data/lib/action_view/helpers/tags/datetime_field.rb +14 -6
  42. data/lib/action_view/helpers/tags/datetime_local_field.rb +11 -2
  43. data/lib/action_view/helpers/tags/grouped_collection_select.rb +3 -0
  44. data/lib/action_view/helpers/tags/month_field.rb +1 -1
  45. data/lib/action_view/helpers/tags/select.rb +4 -1
  46. data/lib/action_view/helpers/tags/select_renderer.rb +56 -0
  47. data/lib/action_view/helpers/tags/time_field.rb +1 -1
  48. data/lib/action_view/helpers/tags/time_zone_select.rb +3 -0
  49. data/lib/action_view/helpers/tags/week_field.rb +1 -1
  50. data/lib/action_view/helpers/tags/weekday_select.rb +3 -0
  51. data/lib/action_view/helpers/tags.rb +2 -0
  52. data/lib/action_view/helpers/text_helper.rb +33 -17
  53. data/lib/action_view/helpers/translation_helper.rb +6 -6
  54. data/lib/action_view/helpers/url_helper.rb +90 -65
  55. data/lib/action_view/helpers.rb +2 -0
  56. data/lib/action_view/layouts.rb +13 -8
  57. data/lib/action_view/log_subscriber.rb +49 -32
  58. data/lib/action_view/lookup_context.rb +29 -13
  59. data/lib/action_view/path_registry.rb +57 -0
  60. data/lib/action_view/path_set.rb +13 -14
  61. data/lib/action_view/railtie.rb +26 -3
  62. data/lib/action_view/record_identifier.rb +16 -9
  63. data/lib/action_view/renderer/abstract_renderer.rb +1 -1
  64. data/lib/action_view/renderer/collection_renderer.rb +9 -1
  65. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +21 -3
  66. data/lib/action_view/renderer/partial_renderer.rb +3 -2
  67. data/lib/action_view/renderer/renderer.rb +2 -0
  68. data/lib/action_view/renderer/streaming_template_renderer.rb +3 -2
  69. data/lib/action_view/renderer/template_renderer.rb +3 -2
  70. data/lib/action_view/rendering.rb +24 -6
  71. data/lib/action_view/ripper_ast_parser.rb +6 -6
  72. data/lib/action_view/routing_url_for.rb +7 -4
  73. data/lib/action_view/template/error.rb +14 -1
  74. data/lib/action_view/template/handlers/builder.rb +4 -4
  75. data/lib/action_view/template/handlers/erb/erubi.rb +23 -27
  76. data/lib/action_view/template/handlers/erb.rb +73 -1
  77. data/lib/action_view/template/handlers.rb +1 -1
  78. data/lib/action_view/template/html.rb +1 -1
  79. data/lib/action_view/template/raw_file.rb +1 -1
  80. data/lib/action_view/template/renderable.rb +1 -1
  81. data/lib/action_view/template/resolver.rb +15 -5
  82. data/lib/action_view/template/text.rb +1 -1
  83. data/lib/action_view/template/types.rb +25 -34
  84. data/lib/action_view/template.rb +227 -53
  85. data/lib/action_view/template_path.rb +2 -0
  86. data/lib/action_view/test_case.rb +174 -21
  87. data/lib/action_view/unbound_template.rb +15 -5
  88. data/lib/action_view/version.rb +1 -1
  89. data/lib/action_view/view_paths.rb +19 -28
  90. data/lib/action_view.rb +4 -1
  91. data/lib/assets/compiled/rails-ujs.js +36 -5
  92. metadata +27 -27
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ module SelectRenderer # :nodoc:
7
+ private
8
+ def select_content_tag(option_tags, options, html_options)
9
+ html_options = html_options.stringify_keys
10
+ [:required, :multiple, :size].each do |prop|
11
+ html_options[prop.to_s] = options.delete(prop) if options.key?(prop) && !html_options.key?(prop.to_s)
12
+ end
13
+
14
+ add_default_name_and_id(html_options)
15
+
16
+ if placeholder_required?(html_options)
17
+ raise ArgumentError, "include_blank cannot be false for a required field." if options[:include_blank] == false
18
+ options[:include_blank] ||= true unless options[:prompt]
19
+ end
20
+
21
+ value = options.fetch(:selected) { value() }
22
+ select = content_tag("select", add_options(option_tags, options, value), html_options)
23
+
24
+ if html_options["multiple"] && options.fetch(:include_hidden, true)
25
+ tag("input", disabled: html_options["disabled"], name: html_options["name"], type: "hidden", value: "", autocomplete: "off") + select
26
+ else
27
+ select
28
+ end
29
+ end
30
+
31
+ def placeholder_required?(html_options)
32
+ # See https://html.spec.whatwg.org/multipage/forms.html#attr-select-required
33
+ html_options["required"] && !html_options["multiple"] && html_options.fetch("size", 1).to_i == 1
34
+ end
35
+
36
+ def add_options(option_tags, options, value = nil)
37
+ if options[:include_blank]
38
+ content = (options[:include_blank] if options[:include_blank].is_a?(String))
39
+ label = (" " unless content)
40
+ option_tags = tag_builder.content_tag_string("option", content, value: "", label: label) + "\n" + option_tags
41
+ end
42
+
43
+ if value.blank? && options[:prompt]
44
+ tag_options = { value: "" }.tap do |prompt_opts|
45
+ prompt_opts[:disabled] = true if options[:disabled] == ""
46
+ prompt_opts[:selected] = true if options[:selected] == ""
47
+ end
48
+ option_tags = tag_builder.content_tag_string("option", prompt_text(options[:prompt]), tag_options) + "\n" + option_tags
49
+ end
50
+
51
+ option_tags
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -10,7 +10,7 @@ module ActionView
10
10
  end
11
11
 
12
12
  private
13
- def format_date(value)
13
+ def format_datetime(value)
14
14
  if @include_seconds
15
15
  value&.strftime("%T.%L")
16
16
  else
@@ -4,6 +4,9 @@ module ActionView
4
4
  module Helpers
5
5
  module Tags # :nodoc:
6
6
  class TimeZoneSelect < Base # :nodoc:
7
+ include SelectRenderer
8
+ include FormOptionsHelper
9
+
7
10
  def initialize(object_name, method_name, template_object, priority_zones, options, html_options)
8
11
  @priority_zones = priority_zones
9
12
  @html_options = html_options
@@ -5,7 +5,7 @@ module ActionView
5
5
  module Tags # :nodoc:
6
6
  class WeekField < DatetimeField # :nodoc:
7
7
  private
8
- def format_date(value)
8
+ def format_datetime(value)
9
9
  value&.strftime("%Y-W%V")
10
10
  end
11
11
  end
@@ -4,6 +4,9 @@ module ActionView
4
4
  module Helpers
5
5
  module Tags # :nodoc:
6
6
  class WeekdaySelect < Base # :nodoc:
7
+ include SelectRenderer
8
+ include FormOptionsHelper
9
+
7
10
  def initialize(object_name, method_name, template_object, options, html_options)
8
11
  @html_options = html_options
9
12
 
@@ -5,6 +5,8 @@ module ActionView
5
5
  module Tags # :nodoc:
6
6
  extend ActiveSupport::Autoload
7
7
 
8
+ autoload :SelectRenderer
9
+
8
10
  eager_autoload do
9
11
  autoload :Base
10
12
  autoload :Translator
@@ -8,8 +8,9 @@ require "action_view/helpers/tag_helper"
8
8
  require "action_view/helpers/output_safety_helper"
9
9
 
10
10
  module ActionView
11
- # = Action View Text Helpers
12
11
  module Helpers # :nodoc:
12
+ # = Action View Text \Helpers
13
+ #
13
14
  # The TextHelper module provides a set of methods for filtering, formatting
14
15
  # and transforming strings, which can reduce the amount of inline Ruby code in
15
16
  # your views. These helper methods extend Action View making them callable
@@ -139,16 +140,19 @@ module ActionView
139
140
  if text.blank? || phrases.blank?
140
141
  text || ""
141
142
  else
142
- match = Array(phrases).map do |p|
143
- Regexp === p ? p.to_s : Regexp.escape(p)
144
- end.join("|")
145
-
146
- if block_given?
147
- text.gsub(/(#{match})(?![^<]*?>)/i, &block)
148
- else
149
- highlighter = options.fetch(:highlighter, '<mark>\1</mark>')
150
- text.gsub(/(#{match})(?![^<]*?>)/i, highlighter)
151
- end
143
+ patterns = Array(phrases).map { |phrase| Regexp === phrase ? phrase : Regexp.escape(phrase) }
144
+ pattern = /(#{patterns.join("|")})/i
145
+ highlighter = options.fetch(:highlighter, '<mark>\1</mark>') unless block
146
+
147
+ text.scan(/<[^>]*|[^<]+/).each do |segment|
148
+ if !segment.start_with?("<")
149
+ if block
150
+ segment.gsub!(pattern, &block)
151
+ else
152
+ segment.gsub!(pattern, highlighter)
153
+ end
154
+ end
155
+ end.join
152
156
  end.html_safe
153
157
  end
154
158
 
@@ -262,13 +266,21 @@ module ActionView
262
266
  # word_wrap('Once upon a time', line_width: 1, break_sequence: "\r\n")
263
267
  # # => Once\r\nupon\r\na\r\ntime
264
268
  def word_wrap(text, line_width: 80, break_sequence: "\n")
265
- text.split("\n").collect! do |line|
266
- line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1#{break_sequence}").rstrip : line
267
- end * break_sequence
269
+ # Match up to `line_width` characters, followed by one of
270
+ # (1) non-newline whitespace plus an optional newline
271
+ # (2) the end of the string, ignoring any trailing newlines
272
+ # (3) a newline
273
+ #
274
+ # -OR-
275
+ #
276
+ # Match an empty line
277
+ pattern = /(.{1,#{line_width}})(?:[^\S\n]+\n?|\n*\Z|\n)|\n/
278
+
279
+ text.gsub(pattern, "\\1#{break_sequence}").chomp!(break_sequence)
268
280
  end
269
281
 
270
282
  # Returns +text+ transformed into HTML using simple formatting rules.
271
- # Two or more consecutive newlines(<tt>\n\n</tt> or <tt>\r\n\r\n</tt>) are
283
+ # Two or more consecutive newlines (<tt>\n\n</tt> or <tt>\r\n\r\n</tt>) are
272
284
  # considered a paragraph and wrapped in <tt><p></tt> tags. One newline
273
285
  # (<tt>\n</tt> or <tt>\r\n</tt>) is considered a linebreak and a
274
286
  # <tt><br /></tt> tag is appended. This method does not remove the
@@ -279,6 +291,7 @@ module ActionView
279
291
  #
280
292
  # ==== Options
281
293
  # * <tt>:sanitize</tt> - If +false+, does not sanitize +text+.
294
+ # * <tt>:sanitize_options</tt> - Any extra options you want appended to the sanitize.
282
295
  # * <tt>:wrapper_tag</tt> - String representing the wrapper tag, defaults to <tt>"p"</tt>
283
296
  #
284
297
  # ==== Examples
@@ -303,10 +316,13 @@ module ActionView
303
316
  #
304
317
  # simple_format("<blink>Blinkable!</blink> It's true.", {}, sanitize: false)
305
318
  # # => "<p><blink>Blinkable!</blink> It's true.</p>"
319
+ #
320
+ # simple_format("<a target=\"_blank\" href=\"http://example.com\">Continue</a>", {}, { sanitize_options: { attributes: %w[target href] } })
321
+ # # => "<p><a target=\"_blank\" href=\"http://example.com\">Continue</a></p>"
306
322
  def simple_format(text, html_options = {}, options = {})
307
- wrapper_tag = options.fetch(:wrapper_tag, :p)
323
+ wrapper_tag = options[:wrapper_tag] || "p"
308
324
 
309
- text = sanitize(text) if options.fetch(:sanitize, true)
325
+ text = sanitize(text, options.fetch(:sanitize_options, {})) if options.fetch(:sanitize, true)
310
326
  paragraphs = split_paragraphs(text)
311
327
 
312
328
  if paragraphs.empty?
@@ -4,14 +4,14 @@ require "action_view/helpers/tag_helper"
4
4
  require "active_support/html_safe_translation"
5
5
 
6
6
  module ActionView
7
- # = Action View Translation Helpers
8
7
  module Helpers # :nodoc:
8
+ # = Action View Translation \Helpers
9
9
  module TranslationHelper
10
10
  extend ActiveSupport::Concern
11
11
 
12
12
  include TagHelper
13
13
 
14
- # Specify whether an error should be raised for missing translations
14
+ # Specify whether an error should be raised for missing translations.
15
15
  singleton_class.attr_accessor :raise_on_missing_translations
16
16
 
17
17
  included do
@@ -90,10 +90,10 @@ module ActionView
90
90
 
91
91
  translated = ActiveSupport::HtmlSafeTranslation.translate(key, **options, default: default)
92
92
 
93
- break translated unless translated.equal?(MISSING_TRANSLATION)
93
+ break translated unless translated == MISSING_TRANSLATION
94
94
 
95
95
  if alternatives.present? && !alternatives.first.is_a?(Symbol)
96
- break alternatives.first && I18n.translate(**options, default: alternatives)
96
+ break alternatives.first && I18n.translate(nil, **options, default: alternatives)
97
97
  end
98
98
 
99
99
  first_key ||= key
@@ -111,7 +111,7 @@ module ActionView
111
111
 
112
112
  # Delegates to <tt>I18n.localize</tt> with no additional functionality.
113
113
  #
114
- # See https://www.rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/Base:localize
114
+ # See https://www.rubydoc.info/gems/i18n/I18n/Backend/Base:localize
115
115
  # for more information.
116
116
  def localize(object, **options)
117
117
  I18n.localize(object, **options)
@@ -119,7 +119,7 @@ module ActionView
119
119
  alias :l :localize
120
120
 
121
121
  private
122
- MISSING_TRANSLATION = Object.new
122
+ MISSING_TRANSLATION = -(2**60)
123
123
  private_constant :MISSING_TRANSLATION
124
124
 
125
125
  NO_DEFAULT = [].freeze
@@ -3,11 +3,13 @@
3
3
  require "active_support/core_ext/array/access"
4
4
  require "active_support/core_ext/hash/keys"
5
5
  require "active_support/core_ext/string/output_safety"
6
+ require "action_view/helpers/content_exfiltration_prevention_helper"
6
7
  require "action_view/helpers/tag_helper"
7
8
 
8
9
  module ActionView
9
- # = Action View URL Helpers
10
10
  module Helpers # :nodoc:
11
+ # = Action View URL \Helpers
12
+ #
11
13
  # Provides a set of methods for making links and getting URLs that
12
14
  # depend on the routing subsystem (see ActionDispatch::Routing).
13
15
  # This allows you to use the same format for links in views
@@ -22,6 +24,7 @@ module ActionView
22
24
  extend ActiveSupport::Concern
23
25
 
24
26
  include TagHelper
27
+ include ContentExfiltrationPreventionHelper
25
28
 
26
29
  module ClassMethods
27
30
  def _url_for_modules
@@ -89,26 +92,11 @@ module ActionView
89
92
  #
90
93
  # ==== Options
91
94
  # * <tt>:data</tt> - This option can be used to add custom data attributes.
92
- # * <tt>method: symbol of HTTP verb</tt> - This modifier will dynamically
93
- # create an HTML form and immediately submit the form for processing using
94
- # the HTTP verb specified. Useful for having links perform a POST operation
95
- # in dangerous actions like deleting a record (which search bots can follow
96
- # while spidering your site). Supported verbs are <tt>:post</tt>, <tt>:delete</tt>, <tt>:patch</tt>, and <tt>:put</tt>.
97
- # Note that if the user has JavaScript disabled, the request will fall back
98
- # to using GET. If <tt>href: '#'</tt> is used and the user has JavaScript
99
- # disabled clicking the link will have no effect. If you are relying on the
100
- # POST behavior, you should check for it in your controller's action by using
101
- # the request object's methods for <tt>post?</tt>, <tt>delete?</tt>, <tt>patch?</tt>, or <tt>put?</tt>.
102
- # * <tt>remote: true</tt> - This will allow the unobtrusive JavaScript
103
- # driver to make an Ajax request to the URL in question instead of following
104
- # the link. The drivers each provide mechanisms for listening for the
105
- # completion of the Ajax request and performing JavaScript operations once
106
- # they're complete
107
95
  #
108
96
  # ==== Examples
109
97
  #
110
98
  # Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments
111
- # and newer RESTful routes. Current Rails style favors RESTful routes whenever possible, so base
99
+ # and newer RESTful routes. Current \Rails style favors RESTful routes whenever possible, so base
112
100
  # your application on resources and use
113
101
  #
114
102
  # link_to "Profile", profile_path(@profile)
@@ -180,28 +168,65 @@ module ActionView
180
168
  # link_to "Nonsense search", searches_path(foo: "bar", baz: "quux")
181
169
  # # => <a href="/searches?foo=bar&baz=quux">Nonsense search</a>
182
170
  #
183
- # The only option specific to +link_to+ (<tt>:method</tt>) is used as follows:
184
- #
185
- # link_to("Destroy", "http://www.example.com", method: :delete)
186
- # # => <a href='http://www.example.com' rel="nofollow" data-method="delete">Destroy</a>
187
- #
188
- # Also you can set any link attributes such as <tt>target</tt>, <tt>rel</tt>, <tt>type</tt>:
171
+ # You can set any link attributes such as <tt>target</tt>, <tt>rel</tt>, <tt>type</tt>:
189
172
  #
190
173
  # link_to "External link", "http://www.rubyonrails.org/", target: "_blank", rel: "nofollow"
191
174
  # # => <a href="http://www.rubyonrails.org/" target="_blank" rel="nofollow">External link</a>
192
175
  #
193
- # ==== Deprecated: Rails UJS attributes
176
+ # ==== Turbo
177
+ #
178
+ # Rails 7 ships with Turbo enabled by default. Turbo provides the following +:data+ options:
179
+ #
180
+ # * <tt>turbo_method: symbol of HTTP verb</tt> - Performs a Turbo link visit
181
+ # with the given HTTP verb. Forms are recommended when performing non-+GET+ requests.
182
+ # Only use <tt>data-turbo-method</tt> where a form is not possible.
194
183
  #
195
- # Prior to Rails 7, Rails shipped with a JavaScript library called @rails/ujs on by default. Following Rails 7,
184
+ # * <tt>turbo_confirm: "question?"</tt> - Adds a confirmation dialog to the link with the
185
+ # given value.
186
+ #
187
+ # {Consult the Turbo Handbook for more information on the options
188
+ # above.}[https://turbo.hotwired.dev/handbook/drive#performing-visits-with-a-different-method]
189
+ #
190
+ # ===== \Examples
191
+ #
192
+ # link_to "Delete profile", @profile, data: { turbo_method: :delete }
193
+ # # => <a href="/profiles/1" data-turbo-method="delete">Delete profile</a>
194
+ #
195
+ # link_to "Visit Other Site", "https://rubyonrails.org/", data: { turbo_confirm: "Are you sure?" }
196
+ # # => <a href="https://rubyonrails.org/" data-turbo-confirm="Are you sure?">Visit Other Site</a>
197
+ #
198
+ # ==== Deprecated: \Rails UJS Attributes
199
+ #
200
+ # Prior to \Rails 7, \Rails shipped with a JavaScript library called <tt>@rails/ujs</tt> on by default. Following \Rails 7,
196
201
  # this library is no longer on by default. This library integrated with the following options:
197
202
  #
198
- # * <tt>confirm: 'question?'</tt> - This will allow the unobtrusive JavaScript
199
- # driver to prompt with the question specified (in this case, the
200
- # resulting text would be <tt>question?</tt>. If the user accepts, the
203
+ # * <tt>method: symbol of HTTP verb</tt> - This modifier will dynamically
204
+ # create an HTML form and immediately submit the form for processing using
205
+ # the HTTP verb specified. Useful for having links perform a POST operation
206
+ # in dangerous actions like deleting a record (which search bots can follow
207
+ # while spidering your site). Supported verbs are <tt>:post</tt>, <tt>:delete</tt>, <tt>:patch</tt>, and <tt>:put</tt>.
208
+ # Note that if the user has JavaScript disabled, the request will fall back
209
+ # to using GET. If <tt>href: '#'</tt> is used and the user has JavaScript
210
+ # disabled clicking the link will have no effect. If you are relying on the
211
+ # POST behavior, you should check for it in your controller's action by using
212
+ # the request object's methods for <tt>post?</tt>, <tt>delete?</tt>, <tt>patch?</tt>, or <tt>put?</tt>.
213
+ # * <tt>remote: true</tt> - This will allow <tt>@rails/ujs</tt>
214
+ # to make an Ajax request to the URL in question instead of following
215
+ # the link.
216
+ #
217
+ # <tt>@rails/ujs</tt> also integrated with the following +:data+ options:
218
+ #
219
+ # * <tt>confirm: "question?"</tt> - This will allow <tt>@rails/ujs</tt>
220
+ # to prompt with the question specified (in this case, the
221
+ # resulting text would be <tt>question?</tt>). If the user accepts, the
201
222
  # link is processed normally, otherwise no action is taken.
202
223
  # * <tt>:disable_with</tt> - Value of this parameter will be used as the
203
- # name for a disabled version of the link. This feature is provided by
204
- # the unobtrusive JavaScript driver.
224
+ # name for a disabled version of the link.
225
+ #
226
+ # ===== \Rails UJS Examples
227
+ #
228
+ # link_to "Remove Profile", profile_path(@profile), method: :delete
229
+ # # => <a href="/profiles/1" rel="nofollow" data-method="delete">Remove Profile</a>
205
230
  #
206
231
  # link_to "Visit Other Site", "http://www.rubyonrails.org/", data: { confirm: "Are you sure?" }
207
232
  # # => <a href="http://www.rubyonrails.org/" data-confirm="Are you sure?">Visit Other Site</a>
@@ -221,9 +246,6 @@ module ActionView
221
246
  # Generates a form containing a single button that submits to the URL created
222
247
  # by the set of +options+. This is the safest method to ensure links that
223
248
  # cause changes to your data are not triggered by search bots or accelerators.
224
- # If the HTML button does not work with your layout, you can also consider
225
- # using the +link_to+ method with the <tt>:method</tt> modifier as described in
226
- # the +link_to+ documentation.
227
249
  #
228
250
  # You can control the form and button behavior with +html_options+. Most
229
251
  # values in +html_options+ are passed through to the button element. For
@@ -237,6 +259,10 @@ module ActionView
237
259
  # The form submits a POST request by default. You can specify a different
238
260
  # HTTP verb via the +:method+ option within +html_options+.
239
261
  #
262
+ # If the HTML button generated from +button_to+ does not work with your layout, you can
263
+ # consider using the +link_to+ method with the +data-turbo-method+
264
+ # attribute as described in the +link_to+ documentation.
265
+ #
240
266
  # ==== Options
241
267
  # The +options+ hash accepts the same options as +url_for+. To generate a
242
268
  # <tt><form></tt> element without an <tt>[action]</tt> attribute, pass
@@ -255,23 +281,11 @@ module ActionView
255
281
  # <tt>:delete</tt>, <tt>:patch</tt>, and <tt>:put</tt>. By default it will be <tt>:post</tt>.
256
282
  # * <tt>:disabled</tt> - If set to true, it will generate a disabled button.
257
283
  # * <tt>:data</tt> - This option can be used to add custom data attributes.
258
- # * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the
259
- # submit behavior. By default this behavior is an ajax submit.
260
284
  # * <tt>:form</tt> - This hash will be form attributes
261
285
  # * <tt>:form_class</tt> - This controls the class of the form within which the submit button will
262
286
  # be placed
263
287
  # * <tt>:params</tt> - \Hash of parameters to be rendered as hidden fields within the form.
264
288
  #
265
- # ==== Data attributes
266
- #
267
- # * <tt>:confirm</tt> - This will use the unobtrusive JavaScript driver to
268
- # prompt with the question specified. If the user accepts, the link is
269
- # processed normally, otherwise no action is taken.
270
- # * <tt>:disable_with</tt> - Value of this parameter will be
271
- # used as the value for a disabled version of the submit
272
- # button when the form is submitted. This feature is provided
273
- # by the unobtrusive JavaScript driver.
274
- #
275
289
  # ==== Examples
276
290
  # <%= button_to "New", action: "new" %>
277
291
  # # => "<form method="post" action="/controller/new" class="button_to">
@@ -308,28 +322,38 @@ module ActionView
308
322
  # # <input name="authenticity_token" type="hidden" value="10f2163b45388899ad4d5ae948988266befcb6c3d1b2451cf657a0c293d605a6" autocomplete="off"/>
309
323
  # # </form>"
310
324
  #
311
- # <%= button_to "Create", { action: "create" }, remote: true, form: { "data-type" => "json" } %>
312
- # # => "<form method="post" action="/images/create" class="button_to" data-remote="true" data-type="json">
325
+ # <%= button_to "Create", { action: "create" }, form: { "data-type" => "json" } %>
326
+ # # => "<form method="post" action="/images/create" class="button_to" data-type="json">
313
327
  # # <button type="submit">Create</button>
314
328
  # # <input name="authenticity_token" type="hidden" value="10f2163b45388899ad4d5ae948988266befcb6c3d1b2451cf657a0c293d605a6" autocomplete="off"/>
315
329
  # # </form>"
316
330
  #
317
- # <%= button_to "Delete Image", { action: "delete", id: @image.id },
318
- # method: :delete, data: { confirm: "Are you sure?" } %>
319
- # # => "<form method="post" action="/images/delete/1" class="button_to">
320
- # # <input type="hidden" name="_method" value="delete" />
321
- # # <button data-confirm='Are you sure?' type="submit">Delete Image</button>
322
- # # <input name="authenticity_token" type="hidden" value="10f2163b45388899ad4d5ae948988266befcb6c3d1b2451cf657a0c293d605a6" autocomplete="off"/>
331
+ # ==== Deprecated: \Rails UJS Attributes
332
+ #
333
+ # Prior to \Rails 7, \Rails shipped with a JavaScript library called <tt>@rails/ujs</tt> on by default. Following \Rails 7,
334
+ # this library is no longer on by default. This library integrated with the following options:
335
+ #
336
+ # * <tt>:remote</tt> - If set to true, will allow <tt>@rails/ujs</tt> to control the
337
+ # submit behavior. By default this behavior is an Ajax submit.
338
+ #
339
+ # <tt>@rails/ujs</tt> also integrated with the following +:data+ options:
340
+ #
341
+ # * <tt>confirm: "question?"</tt> - This will allow <tt>@rails/ujs</tt>
342
+ # to prompt with the question specified (in this case, the
343
+ # resulting text would be <tt>question?</tt>). If the user accepts, the
344
+ # button is processed normally, otherwise no action is taken.
345
+ # * <tt>:disable_with</tt> - Value of this parameter will be
346
+ # used as the value for a disabled version of the submit
347
+ # button when the form is submitted.
348
+ #
349
+ # ===== \Rails UJS Examples
350
+ #
351
+ # <%= button_to "Create", { action: "create" }, remote: true, form: { "data-type" => "json" } %>
352
+ # # => "<form method="post" action="/images/create" class="button_to" data-remote="true" data-type="json">
353
+ # # <button type="submit">Create</button>
354
+ # # <input name="authenticity_token" type="hidden" value="10f2163b45388899ad4d5ae948988266befcb6c3d1b2451cf657a0c293d605a6" autocomplete="off"/>
323
355
  # # </form>"
324
356
  #
325
- # <%= button_to('Destroy', 'http://www.example.com',
326
- # method: :delete, remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' }) %>
327
- # # => "<form class='button_to' method='post' action='http://www.example.com' data-remote='true'>
328
- # # <input name='_method' value='delete' type='hidden' />
329
- # # <button type='submit' data-disable-with='loading...' data-confirm='Are you sure?'>Destroy</button>
330
- # # <input name="authenticity_token" type="hidden" value="10f2163b45388899ad4d5ae948988266befcb6c3d1b2451cf657a0c293d605a6" autocomplete="off"/>
331
- # # </form>"
332
- # #
333
357
  def button_to(name = nil, options = nil, html_options = nil, &block)
334
358
  html_options, options = options, name if block_given?
335
359
  html_options ||= {}
@@ -382,7 +406,8 @@ module ActionView
382
406
  autocomplete: "off")
383
407
  end
384
408
  end
385
- content_tag("form", inner_tags, form_options)
409
+ html = content_tag("form", inner_tags, form_options)
410
+ prevent_content_exfiltration(html)
386
411
  end
387
412
 
388
413
  # Creates a link tag of the given +name+ using a URL created by the set of
@@ -494,10 +519,10 @@ module ActionView
494
519
  # * <tt>:body</tt> - Preset the body of the email.
495
520
  # * <tt>:cc</tt> - Carbon Copy additional recipients on the email.
496
521
  # * <tt>:bcc</tt> - Blind Carbon Copy additional recipients on the email.
497
- # * <tt>:reply_to</tt> - Preset the Reply-To field of the email.
522
+ # * <tt>:reply_to</tt> - Preset the +Reply-To+ field of the email.
498
523
  #
499
524
  # ==== Obfuscation
500
- # Prior to Rails 4.0, +mail_to+ provided options for encoding the address
525
+ # Prior to \Rails 4.0, +mail_to+ provided options for encoding the address
501
526
  # in order to hinder email harvesters. To take advantage of these options,
502
527
  # install the +actionview-encoded_mail_to+ gem.
503
528
  #
@@ -597,7 +622,7 @@ module ActionView
597
622
  # We ignore any extra parameters in the request_uri if the
598
623
  # submitted URL doesn't have any either. This lets the function
599
624
  # work with things like ?order=asc
600
- # the behaviour can be disabled with check_parameters: true
625
+ # the behavior can be disabled with check_parameters: true
601
626
  request_uri = url_string.index("?") || check_parameters ? request.fullpath : request.path
602
627
  request_uri = URI::DEFAULT_PARSER.unescape(request_uri).force_encoding(Encoding::BINARY)
603
628
 
@@ -12,6 +12,7 @@ require "action_view/helpers/asset_tag_helper"
12
12
  require "action_view/helpers/asset_url_helper"
13
13
  require "action_view/helpers/atom_feed_helper"
14
14
  require "action_view/helpers/cache_helper"
15
+ require "action_view/helpers/content_exfiltration_prevention_helper"
15
16
  require "action_view/helpers/controller_helper"
16
17
  require "action_view/helpers/csp_helper"
17
18
  require "action_view/helpers/csrf_helper"
@@ -45,6 +46,7 @@ module ActionView # :nodoc:
45
46
  include AtomFeedHelper
46
47
  include CacheHelper
47
48
  include CaptureHelper
49
+ include ContentExfiltrationPreventionHelper
48
50
  include ControllerHelper
49
51
  include CspHelper
50
52
  include CsrfHelper
@@ -4,12 +4,14 @@ require "action_view/rendering"
4
4
  require "active_support/core_ext/module/redefine_method"
5
5
 
6
6
  module ActionView
7
+ # = Action View \Layouts
8
+ #
7
9
  # Layouts reverse the common pattern of including shared headers and footers in many templates to isolate changes in
8
10
  # repeated setups. The inclusion pattern has pages that look like this:
9
11
  #
10
- # <%= render "shared/header" %>
12
+ # <%= render "application/header" %>
11
13
  # Hello World
12
- # <%= render "shared/footer" %>
14
+ # <%= render "application/footer" %>
13
15
  #
14
16
  # This approach is a decent way of keeping common structures isolated from the changing content, but it's verbose
15
17
  # and if you ever want to change the structure of these two includes, you'll have to change all the templates.
@@ -183,7 +185,7 @@ module ActionView
183
185
  # be rendered directly, without wrapping a layout around the rendered view.
184
186
  #
185
187
  # Both the <tt>:only</tt> and <tt>:except</tt> condition can accept an arbitrary number of method references, so
186
- # #<tt>except: [ :rss, :text_only ]</tt> is valid, as is <tt>except: :rss</tt>.
188
+ # <tt>except: [ :rss, :text_only ]</tt> is valid, as is <tt>except: :rss</tt>.
187
189
  #
188
190
  # == Using a different layout in the action render call
189
191
  #
@@ -210,9 +212,9 @@ module ActionView
210
212
  class_attribute :_layout_conditions, instance_accessor: false, default: {}
211
213
 
212
214
  _write_layout_method
213
- end
214
215
 
215
- delegate :_layout_conditions, to: :class
216
+ delegate :_layout_conditions, to: :class
217
+ end
216
218
 
217
219
  module ClassMethods
218
220
  def inherited(klass) # :nodoc:
@@ -255,14 +257,17 @@ module ActionView
255
257
  # true:: raise an ArgumentError
256
258
  # nil:: Force default layout behavior with inheritance
257
259
  #
258
- # Return value of +Proc+ and +Symbol+ arguments should be +String+, +false+, +true+ or +nil+
260
+ # Return value of +Proc+ and +Symbol+ arguments should be +String+, +false+, +true+, or +nil+
259
261
  # with the same meaning as described above.
262
+ #
260
263
  # ==== Parameters
264
+ #
261
265
  # * <tt>layout</tt> - The layout to use.
262
266
  #
263
267
  # ==== Options (conditions)
264
- # * :only - A list of actions to apply this layout to.
265
- # * :except - Apply this layout to all actions but this one.
268
+ #
269
+ # * +:only+ - A list of actions to apply this layout to.
270
+ # * +:except+ - Apply this layout to all actions but this one.
266
271
  def layout(layout, conditions = {})
267
272
  include LayoutConditions unless conditions.empty?
268
273