actionview 7.0.8.1 → 7.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +235 -362
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/app/assets/javascripts/rails-ujs.esm.js +668 -0
  6. data/app/assets/javascripts/rails-ujs.js +606 -0
  7. data/lib/action_view/base.rb +28 -7
  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 +4 -4
  14. data/lib/action_view/helpers/active_model_helper.rb +1 -1
  15. data/lib/action_view/helpers/asset_tag_helper.rb +130 -46
  16. data/lib/action_view/helpers/asset_url_helper.rb +6 -5
  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 +24 -10
  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 +2 -2
  24. data/lib/action_view/helpers/date_helper.rb +17 -19
  25. data/lib/action_view/helpers/debug_helper.rb +3 -3
  26. data/lib/action_view/helpers/form_helper.rb +43 -18
  27. data/lib/action_view/helpers/form_options_helper.rb +2 -1
  28. data/lib/action_view/helpers/form_tag_helper.rb +43 -9
  29. data/lib/action_view/helpers/javascript_helper.rb +1 -0
  30. data/lib/action_view/helpers/number_helper.rb +2 -1
  31. data/lib/action_view/helpers/output_safety_helper.rb +2 -2
  32. data/lib/action_view/helpers/rendering_helper.rb +1 -1
  33. data/lib/action_view/helpers/sanitize_helper.rb +33 -14
  34. data/lib/action_view/helpers/tag_helper.rb +5 -27
  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 +3 -0
  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 +32 -16
  53. data/lib/action_view/helpers/translation_helper.rb +3 -3
  54. data/lib/action_view/helpers/url_helper.rb +41 -14
  55. data/lib/action_view/helpers.rb +2 -0
  56. data/lib/action_view/layouts.rb +4 -2
  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 +15 -8
  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 +2 -1
  66. data/lib/action_view/renderer/partial_renderer.rb +2 -1
  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 +22 -4
  71. data/lib/action_view/ripper_ast_parser.rb +5 -5
  72. data/lib/action_view/template/error.rb +14 -1
  73. data/lib/action_view/template/handlers/builder.rb +4 -4
  74. data/lib/action_view/template/handlers/erb/erubi.rb +23 -27
  75. data/lib/action_view/template/handlers/erb.rb +73 -1
  76. data/lib/action_view/template/handlers.rb +1 -1
  77. data/lib/action_view/template/html.rb +1 -1
  78. data/lib/action_view/template/raw_file.rb +1 -1
  79. data/lib/action_view/template/renderable.rb +1 -1
  80. data/lib/action_view/template/resolver.rb +10 -2
  81. data/lib/action_view/template/text.rb +1 -1
  82. data/lib/action_view/template/types.rb +25 -34
  83. data/lib/action_view/template.rb +179 -52
  84. data/lib/action_view/template_path.rb +2 -0
  85. data/lib/action_view/test_case.rb +8 -5
  86. data/lib/action_view/unbound_template.rb +15 -5
  87. data/lib/action_view/version.rb +1 -1
  88. data/lib/action_view/view_paths.rb +15 -24
  89. data/lib/action_view.rb +4 -1
  90. metadata +26 -26
data/CHANGELOG.md CHANGED
@@ -1,39 +1,25 @@
1
- ## Rails 7.0.8.1 (February 21, 2024) ##
1
+ ## Rails 7.1.0.beta1 (September 13, 2023) ##
2
2
 
3
- * No changes.
3
+ * Fix `simple_format` with blank `wrapper_tag` option returns plain html tag
4
4
 
5
+ By default `simple_format` method returns the text wrapped with `<p>`. But if we explicitly specify
6
+ the `wrapper_tag: nil` in the options, it returns the text wrapped with `<></>` tag.
5
7
 
6
- ## Rails 7.0.8 (September 09, 2023) ##
7
-
8
- * Fix `form_for` missing the hidden `_method` input for models with a
9
- namespaced route.
10
-
11
- *Hartley McGuire*
12
-
13
- * Fix `render collection: @records, cache: true` inside `jbuilder` templates
14
-
15
- The previous fix that shipped in `7.0.7` assumed template fragments are always strings,
16
- this isn't true with `jbuilder`.
17
-
18
- *Jean Boussier*
19
-
20
- ## Rails 7.0.7.2 (August 22, 2023) ##
21
-
22
- * No changes.
23
-
24
-
25
- ## Rails 7.0.7.1 (August 22, 2023) ##
26
-
27
- * No changes.
28
-
8
+ Before:
29
9
 
30
- ## Rails 7.0.7 (August 09, 2023) ##
10
+ ```ruby
11
+ simple_format("Hello World", {}, { wrapper_tag: nil })
12
+ # <>Hello World</>
13
+ ```
31
14
 
32
- * Fix `render collection: @records, cache: true` to cache fragments as bare strings
15
+ After:
33
16
 
34
- Previously it would incorrectly cache them as Action View buffers.
17
+ ```ruby
18
+ simple_format("Hello World", {}, { wrapper_tag: nil })
19
+ # <p>Hello World</p>
20
+ ```
35
21
 
36
- *Jean Boussier*
22
+ *Akhil G Krishnan*, *Junichi Ito*
37
23
 
38
24
  * Don't double-encode nested `field_id` and `field_name` index values
39
25
 
@@ -42,457 +28,344 @@
42
28
 
43
29
  *Sean Doyle*
44
30
 
31
+ * Allow opting in/out of `Link preload` headers when calling `stylesheet_link_tag` or `javascript_include_tag`
45
32
 
46
- ## Rails 7.0.6 (June 29, 2023) ##
47
-
48
- * No changes.
49
-
50
-
51
- ## Rails 7.0.5.1 (June 26, 2023) ##
52
-
53
- * No changes.
33
+ ```ruby
34
+ # will exclude header, even if setting is enabled:
35
+ javascript_include_tag("http://example.com/all.js", preload_links_header: false)
54
36
 
37
+ # will include header, even if setting is disabled:
38
+ stylesheet_link_tag("http://example.com/all.js", preload_links_header: true)
39
+ ```
55
40
 
56
- ## Rails 7.0.5 (May 24, 2023) ##
41
+ *Alex Ghiculescu*
57
42
 
58
- * `FormBuilder#id` finds id set by `form_for` and `form_with`.
43
+ * Stop generating `Link preload` headers once it has reached 1KB.
59
44
 
60
- *Matt Polito*
45
+ Some proxies have trouble handling large headers, but more importantly preload links
46
+ have diminishing returns so it's preferable not to go overboard with them.
61
47
 
62
- * Allow all available locales for template lookups.
48
+ If tighter control is needed, it's recommended to disable automatic generation of preloads
49
+ and to generate them manually from the controller or from a middleware.
63
50
 
64
- *Ben Dilley*
51
+ *Jean Boussier*
65
52
 
66
- * Choices of `select` can optionally contain html attributes as the last element
67
- of the child arrays when using grouped/nested collections
53
+ * `simple_format` helper now handles a `:sanitize_options` - any extra options you want appending to the sanitize.
68
54
 
69
- ```erb
70
- <%= form.select :foo, [["North America", [["United States","US"],["Canada","CA"]], { disabled: "disabled" }]] %>
71
- # => <select><optgroup label="North America" disabled="disabled"><option value="US">United States</option><option value="CA">Canada</option></optgroup></select>
55
+ Before:
56
+ ```ruby
57
+ simple_format("<a target=\"_blank\" href=\"http://example.com\">Continue</a>")
58
+ # => "<p><a href=\"http://example.com\">Continue</a></p>"
72
59
  ```
73
60
 
74
- *Chris Gunther*
75
-
76
-
77
- ## Rails 7.0.4.3 (March 13, 2023) ##
61
+ After:
62
+ ```ruby
63
+ simple_format("<a target=\"_blank\" href=\"http://example.com\">Continue</a>", {}, { sanitize_options: { attributes: %w[target href] } })
64
+ # => "<p><a target=\"_blank\" href=\"http://example.com\">Continue</a></p>"
65
+ ```
78
66
 
79
- * Ignore certain data-* attributes in rails-ujs when element is contenteditable
67
+ *Andrei Andriichuk*
80
68
 
81
- [CVE-2023-23913]
69
+ * Add support for HTML5 standards-compliant sanitizers, and default to `Rails::HTML5::Sanitizer`
70
+ in the Rails 7.1 configuration if it is supported.
82
71
 
72
+ Action View's HTML sanitizers can be configured by setting
73
+ `config.action_view.sanitizer_vendor`. Supported values are `Rails::HTML4::Sanitizer` or
74
+ `Rails::HTML5::Sanitizer`.
83
75
 
84
- ## Rails 7.0.4.2 (January 24, 2023) ##
76
+ The Rails 7.1 configuration will set this to `Rails::HTML5::Sanitizer` when it is supported, and
77
+ fall back to `Rails::HTML4::Sanitizer`. Previous configurations default to
78
+ `Rails::HTML4::Sanitizer`.
85
79
 
86
- * No changes.
80
+ *Mike Dalessio*
87
81
 
82
+ * `config.dom_testing_default_html_version` controls the HTML parser used by
83
+ `ActionView::TestCase#document_root_element`, which creates the DOM used by the assertions in
84
+ Rails::Dom::Testing.
88
85
 
89
- ## Rails 7.0.4.1 (January 17, 2023) ##
86
+ The Rails 7.1 default configuration opts into the HTML5 parser when it is supported, to better
87
+ represent what the DOM would be in a browser user agent. Previously this test helper always used
88
+ Nokogiri's HTML4 parser.
90
89
 
91
- * No changes.
90
+ *Mike Dalessio*
92
91
 
92
+ * Add support for the HTML picture tag. It supports passing a String, an Array or a Block.
93
+ Supports passing properties directly to the img tag via the `:image` key.
94
+ Since the picture tag requires an img tag, the last element you provide will be used for the img tag.
95
+ For complete control over the picture tag, a block can be passed, which will populate the contents of the tag accordingly.
93
96
 
94
- ## Rails 7.0.4 (September 09, 2022) ##
97
+ Can be used like this for a single source:
98
+ ```erb
99
+ <%= picture_tag("picture.webp") %>
100
+ ```
101
+ which will generate the following:
102
+ ```html
103
+ <picture>
104
+ <img src="/images/picture.webp" />
105
+ </picture>
106
+ ```
95
107
 
96
- * Guard against `ActionView::Helpers::FormTagHelper#field_name` calls with nil
97
- `object_name` arguments. For example:
108
+ For multiple sources:
109
+ ```erb
110
+ <%= picture_tag("picture.webp", "picture.png", :class => "mt-2", :image => { alt: "Image", class: "responsive-img" }) %>
111
+ ```
112
+ will generate:
113
+ ```html
114
+ <picture class="mt-2">
115
+ <source srcset="/images/picture.webp" />
116
+ <source srcset="/images/picture.png" />
117
+ <img alt="Image" class="responsive-img" src="/images/picture.png" />
118
+ </picture>
119
+ ```
98
120
 
121
+ Full control via a block:
99
122
  ```erb
100
- <%= fields do |f| %>
101
- <%= f.field_name :body %>
123
+ <%= picture_tag(:class => "my-class") do %>
124
+ <%= tag(:source, :srcset => image_path("picture.webp")) %>
125
+ <%= tag(:source, :srcset => image_path("picture.png")) %>
126
+ <%= image_tag("picture.png", :alt => "Image") %>
102
127
  <% end %>
103
128
  ```
129
+ will generate:
130
+ ```html
131
+ <picture class="my-class">
132
+ <source srcset="/images/picture.webp" />
133
+ <source srcset="/images/picture.png" />
134
+ <img alt="Image" src="/images/picture.png" />
135
+ </picture>
136
+ ```
104
137
 
105
- *Sean Doyle*
106
-
107
- * Strings returned from `strip_tags` are correctly tagged `html_safe?`
108
-
109
- Because these strings contain no HTML elements and the basic entities are escaped, they are safe
110
- to be included as-is as PCDATA in HTML content. Tagging them as html-safe avoids double-escaping
111
- entities when being concatenated to a SafeBuffer during rendering.
112
-
113
- Fixes [rails/rails-html-sanitizer#124](https://github.com/rails/rails-html-sanitizer/issues/124)
114
-
115
- *Mike Dalessio*
138
+ *Juan Pablo Balarini*
116
139
 
117
- ## Rails 7.0.3.1 (July 12, 2022) ##
140
+ * Remove deprecated support to passing instance variables as locals to partials.
118
141
 
119
- * No changes.
142
+ *Rafael Mendonça França*
120
143
 
144
+ * Remove deprecated constant `ActionView::Path`.
121
145
 
122
- ## Rails 7.0.3 (May 09, 2022) ##
146
+ *Rafael Mendonça França*
123
147
 
124
- * Ensure models passed to `form_for` attempt to call `to_model`.
148
+ * Guard `token_list` calls from escaping HTML too often
125
149
 
126
150
  *Sean Doyle*
127
151
 
128
- ## Rails 7.0.2.4 (April 26, 2022) ##
129
-
130
- * Fix and add protections for XSS in `ActionView::Helpers` and `ERB::Util`.
131
-
132
- Escape dangerous characters in names of tags and names of attributes in the
133
- tag helpers, following the XML specification. Rename the option
134
- `:escape_attributes` to `:escape`, to simplify by applying the option to the
135
- whole tag.
136
-
137
- *Álvaro Martín Fraguas*
138
-
139
- ## Rails 7.0.2.3 (March 08, 2022) ##
140
-
141
- * No changes.
142
-
143
-
144
- ## Rails 7.0.2.2 (February 11, 2022) ##
145
-
146
- * No changes.
147
-
148
-
149
- ## Rails 7.0.2.1 (February 11, 2022) ##
152
+ * `select` can now be called with a single hash containing options and some HTML options
150
153
 
151
- * No changes.
154
+ Previously this would not work as expected:
152
155
 
156
+ ```erb
157
+ <%= select :post, :author, authors, required: true %>
158
+ ```
153
159
 
154
- ## Rails 7.0.2 (February 08, 2022) ##
155
-
156
- * Ensure `preload_link_tag` preloads JavaScript modules correctly.
157
-
158
- *Máximo Mussini*
159
-
160
- * Fix `stylesheet_link_tag` and similar helpers are being used to work in objects with
161
- a `response` method.
162
-
163
- *dark-panda*
164
-
165
-
166
- ## Rails 7.0.1 (January 06, 2022) ##
167
-
168
- * Fix `button_to` to work with a hash parameter as URL.
160
+ Instead you needed to do this:
169
161
 
170
- *MingyuanQin*
162
+ ```erb
163
+ <%= select :post, :author, authors, {}, required: true %>
164
+ ```
171
165
 
172
- * Fix `link_to` with a model passed as an argument twice.
166
+ Now, either form is accepted, for the following HTML attributes: `required`, `multiple`, `size`.
173
167
 
174
168
  *Alex Ghiculescu*
175
169
 
170
+ * Datetime form helpers (`time_field`, `date_field`, `datetime_field`, `week_field`, `month_field`) now accept an instance of Time/Date/DateTime as `:value` option.
176
171
 
177
- ## Rails 7.0.0 (December 15, 2021) ##
178
-
179
- * Support `include_hidden:` option in calls to
180
- `ActionView::Helper::FormBuilder#file_field` with `multiple: true` to
181
- support submitting an empty collection of files.
182
-
183
- ```ruby
184
- form.file_field :attachments, multiple: true
185
- # => <input type="hidden" autocomplete="off" name="post[attachments][]" value="">
186
- <input type="file" multiple="multiple" id="post_attachments" name="post[attachments][]">
187
-
188
- form.file_field :attachments, multiple: true, include_hidden: false
189
- # => <input type="file" multiple="multiple" id="post_attachments" name="post[attachments][]">
172
+ Before:
173
+ ```erb
174
+ <%= form.datetime_field :written_at, value: Time.current.strftime("%Y-%m-%dT%T") %>
190
175
  ```
191
176
 
192
- *Sean Doyle*
193
-
194
- * Fix `number_with_precision(raise: true)` always raising even on valid numbers.
195
-
196
- *Pedro Moreira*
177
+ After:
178
+ ```erb
179
+ <%= form.datetime_field :written_at, value: Time.current %>
180
+ ```
197
181
 
182
+ *Andrey Samsonov*
198
183
 
199
- ## Rails 7.0.0.rc3 (December 14, 2021) ##
184
+ * Choices of `select` can optionally contain html attributes as the last element
185
+ of the child arrays when using grouped/nested collections
200
186
 
201
- * No changes.
187
+ ```erb
188
+ <%= form.select :foo, [["North America", [["United States","US"],["Canada","CA"]], { disabled: "disabled" }]] %>
189
+ # => <select><optgroup label="North America" disabled="disabled"><option value="US">United States</option><option value="CA">Canada</option></optgroup></select>
190
+ ```
202
191
 
192
+ *Chris Gunther*
203
193
 
204
- ## Rails 7.0.0.rc2 (December 14, 2021) ##
194
+ * `check_box_tag` and `radio_button_tag` now accept `checked` as a keyword argument
205
195
 
206
- * No changes.
196
+ This is to make the API more consistent with the `FormHelper` variants. You can now
197
+ provide `checked` as a positional or keyword argument:
207
198
 
208
- ## Rails 7.0.0.rc1 (December 06, 2021) ##
199
+ ```erb
200
+ = check_box_tag "admin", "1", false
201
+ = check_box_tag "admin", "1", checked: false
209
202
 
210
- * Support `fields model: [@nested, @model]` the same way as `form_with model:
211
- [@nested, @model]`.
203
+ = radio_button_tag 'favorite_color', 'maroon', false
204
+ = radio_button_tag 'favorite_color', 'maroon', checked: false
205
+ ```
212
206
 
213
- *Sean Doyle*
207
+ *Alex Ghiculescu*
214
208
 
215
- * Infer HTTP verb `[method]` from a model or Array with model as the first
216
- argument to `button_to` when combined with a block:
209
+ * Allow passing a class to `dom_id`.
210
+ You no longer need to call `new` when passing a class to `dom_id`.
211
+ This makes `dom_id` behave like `dom_class` in this regard.
212
+ Apart from saving a few keystrokes, it prevents Ruby from needing
213
+ to instantiate a whole new object just to generate a string.
217
214
 
215
+ Before:
218
216
  ```ruby
219
- button_to(Workshop.find(1)){ "Update" }
220
- #=> <form method="post" action="/workshops/1" class="button_to">
221
- #=> <input type="hidden" name="_method" value="patch" autocomplete="off" />
222
- #=> <button type="submit">Update</button>
223
- #=> </form>
224
-
225
- button_to([ Workshop.find(1), Session.find(1) ]) { "Update" }
226
- #=> <form method="post" action="/workshops/1/sessions/1" class="button_to">
227
- #=> <input type="hidden" name="_method" value="patch" autocomplete="off" />
228
- #=> <button type="submit">Update</button>
229
- #=> </form>
217
+ dom_id(Post) # => NoMethodError: undefined method `to_key' for Post:Class
230
218
  ```
231
219
 
232
- *Sean Doyle*
233
-
234
- * Support passing a Symbol as the first argument to `FormBuilder#button`:
235
-
220
+ After:
236
221
  ```ruby
237
- form.button(:draft, value: true)
238
- # => <button name="post[draft]" value="true" type="submit">Create post</button>
239
-
240
- form.button(:draft, value: true) do
241
- content_tag(:strong, "Save as draft")
242
- end
243
- # => <button name="post[draft]" value="true" type="submit">
244
- # <strong>Save as draft</strong>
245
- # </button>
222
+ dom_id(Post) # => "new_post"
246
223
  ```
247
224
 
248
- *Sean Doyle*
225
+ *Goulven Champenois*
249
226
 
250
- * Introduce the `field_name` view helper, along with the
251
- `FormBuilder#field_name` counterpart:
227
+ * Report `:locals` as part of the data returned by ActionView render instrumentation.
252
228
 
229
+ Before:
253
230
  ```ruby
254
- form_for @post do |f|
255
- f.field_tag :tag, name: f.field_name(:tag, multiple: true)
256
- # => <input type="text" name="post[tag][]">
257
- end
231
+ {
232
+ identifier: "/Users/adam/projects/notifications/app/views/posts/index.html.erb",
233
+ layout: "layouts/application"
234
+ }
258
235
  ```
259
236
 
260
- *Sean Doyle*
261
-
262
- * Execute the `ActionView::Base.field_error_proc` within the context of the
263
- `ActionView::Base` instance:
264
-
237
+ After:
265
238
  ```ruby
266
- config.action_view.field_error_proc = proc { |html| content_tag(:div, html, class: "field_with_errors") }
239
+ {
240
+ identifier: "/Users/adam/projects/notifications/app/views/posts/index.html.erb",
241
+ layout: "layouts/application",
242
+ locals: {foo: "bar"}
243
+ }
267
244
  ```
268
245
 
269
- *Sean Doyle*
246
+ *Aaron Gough*
270
247
 
271
- * Add support for `button_to ..., authenticity_token: false`
248
+ * Strip `break_sequence` at the end of `word_wrap`.
272
249
 
273
- ```ruby
274
- button_to "Create", Post.new, authenticity_token: false
275
- # => <form class="button_to" method="post" action="/posts"><button type="submit">Create</button></form>
250
+ This fixes a bug where `word_wrap` didn't properly strip off break sequences that had printable characters.
276
251
 
277
- button_to "Create", Post.new, authenticity_token: true
278
- # => <form class="button_to" method="post" action="/posts"><button type="submit">Create</button><input type="hidden" name="form_token" value="abc123..." autocomplete="off" /></form>
252
+ For example, compare the outputs of this template:
279
253
 
280
- button_to "Create", Post.new, authenticity_token: "secret"
281
- # => <form class="button_to" method="post" action="/posts"><button type="submit">Create</button><input type="hidden" name="form_token" value="secret" autocomplete="off" /></form>
254
+ ```erb
255
+ # <%= word_wrap("11 22\n33 44", line_width: 2, break_sequence: "\n# ") %>
282
256
  ```
283
257
 
284
- *Sean Doyle*
285
-
286
- * Support rendering `<form>` elements _without_ `[action]` attributes by:
258
+ Before:
287
259
 
288
- * `form_with url: false` or `form_with ..., html: { action: false }`
289
- * `form_for ..., url: false` or `form_for ..., html: { action: false }`
290
- * `form_tag false` or `form_tag ..., action: false`
291
- * `button_to "...", false` or `button_to(false) { ... }`
260
+ ```
261
+ # 11
262
+ # 22
263
+ #
264
+ # 33
265
+ # 44
266
+ #
267
+ ```
292
268
 
293
- *Sean Doyle*
269
+ After:
294
270
 
295
- * Add `:day_format` option to `date_select`
271
+ ```
272
+ # 11
273
+ # 22
274
+ # 33
275
+ # 44
276
+ ```
296
277
 
297
- date_select("article", "written_on", day_format: ->(day) { day.ordinalize })
298
- # generates day options like <option value="1">1st</option>\n<option value="2">2nd</option>...
278
+ *Max Chernyak*
299
279
 
300
- *Shunichi Ikegami*
280
+ * Allow templates to set strict `locals`.
301
281
 
302
- * Allow `link_to` helper to infer link name from `Model#to_s` when it
303
- is used with a single argument:
282
+ By default, templates will accept any `locals` as keyword arguments. To define what `locals` a template accepts, add a `locals` magic comment:
304
283
 
305
- link_to @profile
306
- #=> <a href="/profiles/1">Eileen</a>
284
+ ```erb
285
+ <%# locals: (message:) -%>
286
+ <%= message %>
287
+ ```
307
288
 
308
- This assumes the model class implements a `to_s` method like this:
289
+ Default values can also be provided:
309
290
 
310
- class Profile < ApplicationRecord
311
- # ...
312
- def to_s
313
- name
314
- end
315
- end
291
+ ```erb
292
+ <%# locals: (message: "Hello, world!") -%>
293
+ <%= message %>
294
+ ```
316
295
 
317
- Previously you had to supply a second argument even if the `Profile`
318
- model implemented a `#to_s` method that called the `name` method.
296
+ Or `locals` can be disabled entirely:
319
297
 
320
- link_to @profile, @profile.name
321
- #=> <a href="/profiles/1">Eileen</a>
298
+ ```erb
299
+ <%# locals: () %>
300
+ ```
322
301
 
323
- *Olivier Lacan*
302
+ *Joel Hawksley*
324
303
 
325
- * Support svg unpaired tags for `tag` helper.
304
+ * Add `include_seconds` option for `datetime_local_field`
326
305
 
327
- tag.svg { tag.use('href' => "#cool-icon") }
328
- # => <svg><use href="#cool-icon"></svg>
306
+ This allows to omit seconds part in the input field, by passing `include_seconds: false`
329
307
 
330
- *Oleksii Vasyliev*
308
+ *Wojciech Wnętrzak*
331
309
 
310
+ * Guard against `ActionView::Helpers::FormTagHelper#field_name` calls with nil
311
+ `object_name` arguments. For example:
332
312
 
333
- ## Rails 7.0.0.alpha2 (September 15, 2021) ##
313
+ ```erb
314
+ <%= fields do |f| %>
315
+ <%= f.field_name :body %>
316
+ <% end %>
317
+ ```
334
318
 
335
- * No changes.
319
+ *Sean Doyle*
336
320
 
321
+ * Strings returned from `strip_tags` are correctly tagged `html_safe?`
337
322
 
338
- ## Rails 7.0.0.alpha1 (September 15, 2021) ##
323
+ Because these strings contain no HTML elements and the basic entities are escaped, they are safe
324
+ to be included as-is as PCDATA in HTML content. Tagging them as html-safe avoids double-escaping
325
+ entities when being concatenated to a SafeBuffer during rendering.
339
326
 
340
- * Improves the performance of ActionView::Helpers::NumberHelper formatters by avoiding the use of
341
- exceptions as flow control.
327
+ Fixes [rails/rails-html-sanitizer#124](https://github.com/rails/rails-html-sanitizer/issues/124)
342
328
 
343
329
  *Mike Dalessio*
344
330
 
345
- * `preload_link_tag` properly inserts `as` attributes for files with `image` MIME types, such as JPG or SVG.
346
-
347
- *Nate Berkopec*
331
+ * Move `convert_to_model` call from `form_for` into `form_with`
348
332
 
349
- * Add `weekday_options_for_select` and `weekday_select` helper methods. Also adds `weekday_select` to `FormBuilder`.
333
+ Now that `form_for` is implemented in terms of `form_with`, remove the
334
+ `convert_to_model` call from `form_for`.
350
335
 
351
- *Drew Bragg*, *Dana Kashubeck*, *Kasper Timm Hansen*
352
-
353
- * Add `caching?` helper that returns whether the current code path is being cached and `uncacheable!` to denote helper methods that can't participate in fragment caching.
354
-
355
- *Ben Toews*, *John Hawthorn*, *Kasper Timm Hansen*, *Joel Hawksley*
356
-
357
- * Add `include_seconds` option for `time_field`.
358
-
359
- <%= form.time_field :foo, include_seconds: false %>
360
- # => <input value="16:22" type="time" />
361
-
362
- Default includes seconds:
363
-
364
- <%= form.time_field :foo %>
365
- # => <input value="16:22:01.440" type="time" />
366
-
367
- This allows you to take advantage of [different rendering options](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time#time_value_format) in some browsers.
368
-
369
- *Alex Ghiculescu*
370
-
371
- * Improve error messages when template file does not exist at absolute filepath.
372
-
373
- *Ted Whang*
374
-
375
- * Add `:country_code` option to `sms_to` for consistency with `phone_to`.
376
-
377
- *Jonathan Hefner*
378
-
379
- * OpenSSL constants are now used for Digest computations.
336
+ *Sean Doyle*
380
337
 
381
- *Dirkjan Bussink*
338
+ * Fix and add protections for XSS in `ActionView::Helpers` and `ERB::Util`.
382
339
 
383
- * The `translate` helper now passes `default` values that aren't
384
- translation keys through `I18n.translate` for interpolation.
340
+ Escape dangerous characters in names of tags and names of attributes in the
341
+ tag helpers, following the XML specification. Rename the option
342
+ `:escape_attributes` to `:escape`, to simplify by applying the option to the
343
+ whole tag.
385
344
 
386
- *Jonathan Hefner*
345
+ *Álvaro Martín Fraguas*
387
346
 
388
- * Adds option `extname` to `stylesheet_link_tag` to skip default
389
- `.css` extension appended to the stylesheet path.
347
+ * Extend audio_tag and video_tag to accept Active Storage attachments.
390
348
 
391
- Before:
349
+ Now it's possible to write
392
350
 
393
351
  ```ruby
394
- stylesheet_link_tag "style.less"
395
- # <link href="/stylesheets/style.less.scss" rel="stylesheet">
352
+ audio_tag(user.audio_file)
353
+ video_tag(user.video_file)
396
354
  ```
397
355
 
398
- After:
356
+ Instead of
399
357
 
400
358
  ```ruby
401
- stylesheet_link_tag "style.less", extname: false, skip_pipeline: true, rel: "stylesheet/less"
402
- # <link href="/stylesheets/style.less" rel="stylesheet/less">
359
+ audio_tag(polymorphic_path(user.audio_file))
360
+ video_tag(polymorphic_path(user.video_file))
403
361
  ```
404
362
 
405
- *Abhay Nikam*
406
-
407
- * Deprecate `render` locals to be assigned to instance variables.
408
-
409
- *Petrik de Heus*
410
-
411
- * Remove legacy default `media=screen` from `stylesheet_link_tag`.
412
-
413
- *André Luis Leal Cardoso Junior*
363
+ `image_tag` already supported that, so this follows the same pattern.
414
364
 
415
- * Change `ActionView::Helpers::FormBuilder#button` to transform `formmethod`
416
- attributes into `_method="$VERB"` Form Data to enable varied same-form actions:
365
+ *Matheus Richard*
417
366
 
418
- <%= form_with model: post, method: :put do %>
419
- <%= form.button "Update" %>
420
- <%= form.button "Delete", formmethod: :delete %>
421
- <% end %>
422
- <%# => <form action="posts/1">
423
- => <input type="hidden" name="_method" value="put">
424
- => <button type="submit">Update</button>
425
- => <button type="submit" formmethod="post" name="_method" value="delete">Delete</button>
426
- => </form>
427
- %>
428
-
429
- *Sean Doyle*
430
-
431
- * Change `ActionView::Helpers::UrlHelper#button_to` to *always* render a
432
- `<button>` element, regardless of whether or not the content is passed as
433
- the first argument or as a block.
434
-
435
- <%= button_to "Delete", post_path(@post), method: :delete %>
436
- # => <form action="/posts/1"><input type="hidden" name="_method" value="delete"><button type="submit">Delete</button></form>
437
-
438
- <%= button_to post_path(@post), method: :delete do %>
439
- Delete
440
- <% end %>
441
- # => <form action="/posts/1"><input type="hidden" name="_method" value="delete"><button type="submit">Delete</button></form>
442
-
443
- *Sean Doyle*, *Dusan Orlovic*
444
-
445
- * Add `config.action_view.preload_links_header` to allow disabling of
446
- the `Link` header being added by default when using `stylesheet_link_tag`
447
- and `javascript_include_tag`.
448
-
449
- *Andrew White*
450
-
451
- * The `translate` helper now resolves `default` values when a `nil` key is
452
- specified, instead of always returning `nil`.
453
-
454
- *Jonathan Hefner*
455
-
456
- * Add `config.action_view.image_loading` to configure the default value of
457
- the `image_tag` `:loading` option.
458
-
459
- By setting `config.action_view.image_loading = "lazy"`, an application can opt in to
460
- lazy loading images sitewide, without changing view code.
461
-
462
- *Jonathan Hefner*
463
-
464
- * `ActionView::Helpers::FormBuilder#id` returns the value
465
- of the `<form>` element's `id` attribute. With a `method` argument, returns
466
- the `id` attribute for a form field with that name.
467
-
468
- <%= form_for @post do |f| %>
469
- <%# ... %>
470
-
471
- <% content_for :sticky_footer do %>
472
- <%= form.button(form: f.id) %>
473
- <% end %>
474
- <% end %>
475
-
476
- *Sean Doyle*
477
-
478
- * `ActionView::Helpers::FormBuilder#field_id` returns the value generated by
479
- the FormBuilder for the given attribute name.
480
-
481
- <%= form_for @post do |f| %>
482
- <%= f.label :title %>
483
- <%= f.text_field :title, aria: { describedby: f.field_id(:title, :error) } %>
484
- <%= tag.span("is blank", id: f.field_id(:title, :error) %>
485
- <% end %>
486
-
487
- *Sean Doyle*
488
-
489
- * Add `tag.attributes` to transform a Hash into HTML Attributes, ready to be
490
- interpolated into ERB.
491
-
492
- <input <%= tag.attributes(type: :text, aria: { label: "Search" }) %> >
493
- # => <input type="text" aria-label="Search">
367
+ * Ensure models passed to `form_for` attempt to call `to_model`.
494
368
 
495
369
  *Sean Doyle*
496
370
 
497
-
498
- Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/actionview/CHANGELOG.md) for previous changes.
371
+ Please check [7-0-stable](https://github.com/rails/rails/blob/7-0-stable/actionview/CHANGELOG.md) for previous changes.