actionview 7.2.3.1 → 8.1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +198 -109
  3. data/lib/action_view/base.rb +5 -2
  4. data/lib/action_view/buffers.rb +1 -1
  5. data/lib/action_view/dependency_tracker/erb_tracker.rb +37 -28
  6. data/lib/action_view/dependency_tracker/ruby_tracker.rb +3 -20
  7. data/lib/action_view/dependency_tracker/wildcard_resolver.rb +32 -0
  8. data/lib/action_view/dependency_tracker.rb +7 -1
  9. data/lib/action_view/gem_version.rb +3 -3
  10. data/lib/action_view/helpers/asset_tag_helper.rb +21 -2
  11. data/lib/action_view/helpers/atom_feed_helper.rb +0 -2
  12. data/lib/action_view/helpers/cache_helper.rb +8 -0
  13. data/lib/action_view/helpers/capture_helper.rb +2 -2
  14. data/lib/action_view/helpers/controller_helper.rb +6 -2
  15. data/lib/action_view/helpers/date_helper.rb +20 -3
  16. data/lib/action_view/helpers/form_helper.rb +77 -77
  17. data/lib/action_view/helpers/form_options_helper.rb +42 -36
  18. data/lib/action_view/helpers/form_tag_helper.rb +35 -25
  19. data/lib/action_view/helpers/javascript_helper.rb +5 -1
  20. data/lib/action_view/helpers/number_helper.rb +14 -0
  21. data/lib/action_view/helpers/rendering_helper.rb +160 -50
  22. data/lib/action_view/helpers/sanitize_helper.rb +12 -1
  23. data/lib/action_view/helpers/tag_helper.rb +70 -77
  24. data/lib/action_view/helpers/tags/base.rb +11 -9
  25. data/lib/action_view/helpers/tags/check_box.rb +9 -3
  26. data/lib/action_view/helpers/tags/collection_check_boxes.rb +4 -3
  27. data/lib/action_view/helpers/tags/collection_helpers.rb +11 -1
  28. data/lib/action_view/helpers/tags/datetime_field.rb +1 -1
  29. data/lib/action_view/helpers/tags/file_field.rb +7 -2
  30. data/lib/action_view/helpers/tags/hidden_field.rb +1 -1
  31. data/lib/action_view/helpers/tags/label.rb +3 -10
  32. data/lib/action_view/helpers/tags/radio_button.rb +1 -1
  33. data/lib/action_view/helpers/tags/select.rb +6 -1
  34. data/lib/action_view/helpers/tags/select_renderer.rb +6 -4
  35. data/lib/action_view/helpers/tags/text_area.rb +1 -1
  36. data/lib/action_view/helpers/tags/text_field.rb +1 -1
  37. data/lib/action_view/helpers/tags/week_field.rb +1 -1
  38. data/lib/action_view/helpers/text_helper.rb +23 -7
  39. data/lib/action_view/helpers/translation_helper.rb +6 -1
  40. data/lib/action_view/helpers/url_helper.rb +39 -13
  41. data/lib/action_view/layouts.rb +1 -1
  42. data/lib/action_view/locale/en.yml +3 -0
  43. data/lib/action_view/log_subscriber.rb +1 -4
  44. data/lib/action_view/railtie.rb +12 -1
  45. data/lib/action_view/record_identifier.rb +22 -1
  46. data/lib/action_view/render_parser/prism_render_parser.rb +13 -1
  47. data/lib/action_view/render_parser/ripper_render_parser.rb +10 -1
  48. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +5 -1
  49. data/lib/action_view/renderer/partial_renderer.rb +16 -0
  50. data/lib/action_view/renderer/streaming_template_renderer.rb +8 -2
  51. data/lib/action_view/rendering.rb +2 -3
  52. data/lib/action_view/structured_event_subscriber.rb +97 -0
  53. data/lib/action_view/template/error.rb +7 -3
  54. data/lib/action_view/template/handlers/erb/erubi.rb +1 -1
  55. data/lib/action_view/template/handlers/erb.rb +37 -12
  56. data/lib/action_view/template/raw_file.rb +4 -0
  57. data/lib/action_view/template/resolver.rb +0 -1
  58. data/lib/action_view/template.rb +12 -6
  59. data/lib/action_view/test_case.rb +68 -55
  60. data/lib/action_view.rb +16 -0
  61. metadata +20 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61f8e3426843a85e006134bb5d330f91e09457e3392025afab472d470d706929
4
- data.tar.gz: c066f5cc2718465d6f24a8c81ee5361c3c9fcbef2288a8d04b77334e9c724ad9
3
+ metadata.gz: 4ad9b7f3e9b8677cd772d696b4056bda5f44b3cb2074877698060d83eeb8f501
4
+ data.tar.gz: 6d484d054ced5d8990d0ae4b8134879eb192fea59540f8c6f1dd112ed946ec06
5
5
  SHA512:
6
- metadata.gz: 0a9f2a3f39681a4687a4b8a42b10e00be43c0ee413037c9f236b3bbc04961c8d9993ee955bb0b940a5f05c0024c8f17abb3106d4420f0dea593dd020f038df55
7
- data.tar.gz: b259ce7c6e668708a25ca4e61551bbe65aee7c898cf6c2da3ba0d2c40f64e6ccc5adc2067f817e95ac1f913edbb34b9e75ec4de89e058899c7644ecf4fbf5fb5
6
+ metadata.gz: 47f094fac7bbc29736cf46dcaa570b42d25cdee803cdd522ae81e37a8351f029991b82099a3d4b64c253ae396412e1f112feb509f2e941f4bf806bcab4a95272
7
+ data.tar.gz: 07ee062127ab3554407ea34d293611e347789e5cd65012340302b7a690e18b01ce6630d85483be9eb5e575869df10a3808891ebd98d14ceb674499acdf904594
data/CHANGELOG.md CHANGED
@@ -1,209 +1,298 @@
1
- ## Rails 7.2.3.1 (March 23, 2026) ##
1
+ ## Rails 8.1.4.1 (November 03, 2026) ##
2
2
 
3
- * Skip blank attribute names in tag helpers to avoid generating invalid HTML.
3
+ * Skip attribute names in tag helpers that are blank once converted to a
4
+ string.
4
5
 
5
- [CVE-2026-33168]
6
+ A Symbol such as `:" "` is not blank, because `Symbol#blank?` is
7
+ `Symbol#empty?`, so it reached the escaping step and produced an attribute
8
+ with no name. The asset helpers symbolize their keys, so an ordinary String
9
+ key reached the same place.
10
+
11
+ [GHSA-68p9-83h6-5wpj]
6
12
 
7
13
  *Mike Dalessio*
8
14
 
15
+ * Fix `strip_tags` to encode `"` and `'` in its output.
9
16
 
10
- ## Rails 7.2.3 (October 28, 2025) ##
17
+ `strip_tags` returns an `html_safe` string, but was not encoding quotation
18
+ marks. The method now encodes all five HTML-significant characters (`&`,
19
+ `<`, `>`, `"`, `'`), consistent with the existing `html_safe` convention.
11
20
 
12
- * Fix `javascript_include_tag` `type` option to accept either strings and symbols.
21
+ Output used outside HTML, such as in a text template or JSON, now contains
22
+ `&quot;` and `&#39;` where it contained `"` and `'`. `CGI.unescapeHTML`
23
+ decodes them.
13
24
 
14
- ```ruby
15
- javascript_include_tag "application", type: :module
16
- javascript_include_tag "application", type: "module"
17
- ```
25
+ [GHSA-rq8q-p985-fjq7]
18
26
 
19
- Previously, only the string value was recoginized.
27
+ *Mike Dalessio*
20
28
 
21
- *Jean Boussier*
29
+ * Escape the matched phrase before substituting it into `highlight`'s
30
+ `:highlighter`.
22
31
 
23
- * Fix `excerpt` helper with non-whitespace separator.
32
+ A match was copied into each `\1` of the highlighter as it appeared in
33
+ the sanitized text, which keeps `"` and `'` as they are, so a match
34
+ containing a quote ended a quoted attribute value such as the
35
+ documented `'<a href="search?q=\1">\1</a>'` and added attributes of
36
+ its own. Each substituted group now goes through
37
+ `ERB::Util.html_escape_once`, so quotes in a match render as `&quot;`
38
+ and `&#39;`. Only the numbered placeholders `\0` to `\9` are expanded,
39
+ and a match never replaces the `>` that closes a tag.
24
40
 
25
- *Jonathan Hefner*
41
+ [GHSA-v6rj-xm57-3p59]
26
42
 
27
- * Respect `html_options[:form]` when `collection_checkboxes` generates the
28
- hidden `<input>`.
43
+ *Jeremy Daer*
29
44
 
30
- *Riccardo Odone*
45
+ * Require rails-html-sanitizer 1.7.2 or later.
31
46
 
32
- * Layouts have access to local variables passed to `render`.
47
+ With the HTML5 sanitizer, Nokogiri before 1.19.5 left `<` and `>`
48
+ unescaped in attribute values. `highlight` and `simple_format`, which
49
+ edit the sanitized HTML as a string, could then turn markup inside an
50
+ attribute value into live elements. rails-html-sanitizer 1.7.2 requires
51
+ Loofah 2.25.3, which requires Nokogiri 1.19.5.
33
52
 
34
- This fixes #31680 which was a regression in Rails 5.1.
53
+ [GHSA-2p2f-4rq4-gjwc]
35
54
 
36
55
  *Mike Dalessio*
37
56
 
38
- * Argument errors related to strict locals in templates now raise an
39
- `ActionView::StrictLocalsError`, and all other argument errors are reraised as-is.
57
+ ## Rails 8.1.4 (September 24, 2026) ##
40
58
 
41
- Previously, any `ArgumentError` raised during template rendering was swallowed during strict
42
- local error handling, so that an `ArgumentError` unrelated to strict locals (e.g., a helper
43
- method invoked with incorrect arguments) would be replaced by a similar `ArgumentError` with an
44
- unrelated backtrace, making it difficult to debug templates.
59
+ * Fix non-ASCII strict locals defaults rendering as mojibake.
45
60
 
46
- Now, any `ArgumentError` unrelated to strict locals is reraised, preserving the original
47
- backtrace for developers.
61
+ When a template declared a non-ASCII default in its `locals:` magic comment
62
+ and its body was ASCII-only, the handler returned ASCII-8BIT code and the
63
+ compiled method definition was retagged with it, corrupting the default.
48
64
 
49
- Also note that `ActionView::StrictLocalsError` is a subclass of `ArgumentError`, so any existing
50
- code that rescues `ArgumentError` will continue to work.
65
+ *Carlos Daniel Pohlod*
51
66
 
52
- Fixes #52227.
67
+ * Fix the `:ruby` render tracker not being registered for ERB templates when
68
+ `eager_load` is enabled.
53
69
 
54
- *Mike Dalessio*
70
+ *Gabriel Quaresma*
55
71
 
56
- * Fix stack overflow error in dependency tracker when dealing with circular dependencies
72
+ * Fix `Encoding::CompatibilityError` when digesting templates with non-ASCII
73
+ content via `DependencyTracker::RubyTracker`.
57
74
 
58
- *Jean Boussier*
75
+ File-backed templates are loaded as ASCII-8BIT. `RubyTracker` now passes
76
+ `template.encode!` to the handler (matching `Template#compiled_source`) so
77
+ handlers such as Haml/Temple can concatenate static UTF-8 strings without
78
+ raising. Fixes #58203.
59
79
 
60
- * Fix a crash in ERB template error highlighting when the error occurs on a
61
- line in the compiled template that is past the end of the source template.
80
+ *Edil Talantbek uulu*
62
81
 
63
- *Martin Emde*
82
+ * Fix `week_field` to not emit invalid week strings at ISO year boundaries.
64
83
 
65
- * Improve reliability of ERB template error highlighting.
66
- Fix infinite loops and crashes in highlighting and
67
- improve tolerance for alternate ERB handlers.
84
+ *Kenta Ishizaki*
68
85
 
69
- *Martin Emde*
86
+ * Fix `ActionView::TestCase#render` to reset `rendered`.
87
+ The behavior was changed when memoization was added in #51093. Now it once again conforms to the documentation.
70
88
 
89
+ *Jeroen Versteeg*
71
90
 
72
- ## Rails 7.2.2.2 (August 13, 2025) ##
91
+ * Fix `FormBuilder#to_partial_path` returning `nil` for subclasses whose
92
+ name does not end in `Builder`.
73
93
 
74
- * No changes.
94
+ *Kenta Ishizaki*
95
+
96
+ * Fix `collection_radio_buttons` and `collection_check_boxes` generating
97
+ a label `for` attribute that does not match the input `id` when a
98
+ collection value is `nil`.
99
+
100
+ *Kenta Ishizaki*
75
101
 
76
102
 
77
- ## Rails 7.2.2.1 (December 10, 2024) ##
103
+ ## Rails 8.1.3.1 (July 29, 2026) ##
78
104
 
79
105
  * No changes.
80
106
 
81
107
 
82
- ## Rails 7.2.2 (October 30, 2024) ##
108
+ ## Rails 8.1.3 (March 24, 2026) ##
83
109
 
84
- * No changes.
110
+ * Fix encoding errors for string locals containing non-ASCII characters.
85
111
 
112
+ *Kataoka Katsuki*
86
113
 
87
- ## Rails 7.2.1.2 (October 23, 2024) ##
114
+ * Fix collection caching to only forward `expires_in` argument if explicitly set.
88
115
 
89
- * No changes.
116
+ *Pieter Visser*
90
117
 
118
+ ## Rails 8.1.2.1 (March 23, 2026) ##
91
119
 
92
- ## Rails 7.2.1.1 (October 15, 2024) ##
120
+ * Fix possible XSS in DebugExceptions middleware
93
121
 
94
- * No changes.
122
+ [CVE-2026-33167]
95
123
 
124
+ *John Hawthorn*
96
125
 
97
- ## Rails 7.2.1 (August 22, 2024) ##
126
+ * Skip blank attribute names in tag helpers to avoid generating invalid HTML.
98
127
 
99
- * No changes.
128
+ [CVE-2026-33168]
129
+
130
+ *Mike Dalessio*
131
+
132
+
133
+ ## Rails 8.1.2 (January 08, 2026) ##
134
+
135
+ * Fix `file_field` to join mime types with a comma when provided as Array
136
+
137
+ ```ruby
138
+ file_field(:article, :image, accept: ['image/png', 'image/gif', 'image/jpeg'])
139
+ ```
140
+
141
+ Now behaves likes:
100
142
 
143
+ ```
144
+ file_field(:article, :image, accept: 'image/png,image/gif,image/jpeg')
145
+ ```
146
+
147
+ *Bogdan Gusiev*
148
+
149
+ * Fix strict locals parsing to handle multiline definitions.
150
+
151
+ *Said Kaldybaev*
152
+
153
+ * Fix `content_security_policy_nonce` error in mailers when using `content_security_policy_nonce_auto` setting.
101
154
 
102
- ## Rails 7.2.0 (August 09, 2024) ##
155
+ The `content_security_policy_nonce helper` is provided by `ActionController::ContentSecurityPolicy`, and it relies on `request.content_security_policy_nonc`e. Mailers lack both the module and the request object.
103
156
 
104
- * Fix templates with strict locals to also include `local_assigns`.
157
+ *Jarrett Lusso*
105
158
 
106
- Previously templates defining strict locals wouldn't receive the `local_assigns`
107
- hash.
108
159
 
109
- *Jean Boussier*
160
+ ## Rails 8.1.1 (October 28, 2025) ##
110
161
 
111
- * Add queries count to template rendering instrumentation.
162
+ * Respect `remove_hidden_field_autocomplete` config in form builder `hidden_field`.
112
163
 
164
+ *Rafael Mendonça França*
165
+
166
+
167
+ ## Rails 8.1.0 (October 22, 2025) ##
168
+
169
+ * The BEGIN template annotation/comment was previously printed on the same line as the following element. We now insert a newline inside the comment so it spans two lines without adding visible whitespace to the HTML output to enhance readability.
170
+
171
+ Before:
172
+ ```
173
+ <!-- BEGIN /Users/siaw23/Desktop/rails/actionview/test/fixtures/actionpack/test/greeting.html.erb --><p>This is grand!</p>
113
174
  ```
114
- # Before
115
- Completed 200 OK in 3804ms (Views: 41.0ms | ActiveRecord: 33.5ms | Allocations: 112788)
116
175
 
117
- # After
118
- Completed 200 OK in 3804ms (Views: 41.0ms | ActiveRecord: 33.5ms (2 queries, 1 cached) | Allocations: 112788)
176
+ After:
177
+ ```
178
+ <!-- BEGIN /Users/siaw23/Desktop/rails/actionview/test/fixtures/actionpack/test/greeting.html.erb
179
+ --><p>This is grand!</p>
119
180
  ```
181
+ *Emmanuel Hayford*
120
182
 
121
- *fatkodima*
183
+ * Add structured events for Action View:
184
+ - `action_view.render_template`
185
+ - `action_view.render_partial`
186
+ - `action_view.render_layout`
187
+ - `action_view.render_collection`
188
+ - `action_view.render_start`
122
189
 
123
- * Raise `ArgumentError` if `:renderable` object does not respond to `#render_in`.
190
+ *Gannon McGibbon*
124
191
 
125
- *Sean Doyle*
192
+ * Fix label with `for` option not getting prefixed by form `namespace` value
126
193
 
127
- * Add the `nonce: true` option for `stylesheet_link_tag` helper to support automatic nonce generation for Content Security Policy.
194
+ *Abeid Ahmed*, *Hartley McGuire*
128
195
 
129
- Works the same way as `javascript_include_tag nonce: true` does.
196
+ * Add `fetchpriority` to Link headers to match HTML generated by `preload_link_tag`.
130
197
 
131
- *Akhil G Krishnan*, *AJ Esler*
198
+ *Guillermo Iguaran*
132
199
 
133
- * Parse `ActionView::TestCase#rendered` HTML content as `Nokogiri::XML::DocumentFragment` instead of `Nokogiri::XML::Document`.
200
+ * Add CSP `nonce` to Link headers generated by `preload_link_tag`.
134
201
 
135
- *Sean Doyle*
202
+ *Alexander Gitter*
136
203
 
137
- * Rename `ActionView::TestCase::Behavior::Content` to `ActionView::TestCase::Behavior::RenderedViewContent`.
204
+ * Allow `current_page?` to match against specific HTTP method(s) with a `method:` option.
138
205
 
139
- Make `RenderedViewContent` inherit from `String`. Make private API with `:nodoc:`
206
+ *Ben Sheldon*
140
207
 
141
- *Sean Doyle*
208
+ * Remove `autocomplete="off"` on hidden inputs generated by the following
209
+ tags:
142
210
 
143
- * Deprecate passing `nil` as value for the `model:` argument to the `form_with` method.
211
+ * `form_tag`, `token_tag`, `method_tag`
144
212
 
145
- *Collin Jilbert*
213
+ As well as the hidden parameter fields included in `button_to`,
214
+ `check_box`, `select` (with `multiple`) and `file_field` forms.
146
215
 
147
- * Alias `field_set_tag` helper to `fieldset_tag` to match `<fieldset>` element.
216
+ *nkulway*
148
217
 
149
- *Sean Doyle*
218
+ * Enable configuring the strategy for tracking dependencies between Action
219
+ View templates.
150
220
 
151
- * Deprecate passing content to void elements when using `tag.br` type tag builders.
221
+ The existing `:regex` strategy is kept as the default, but with
222
+ `load_defaults 8.1` the strategy will be `:ruby` (using a real Ruby parser).
152
223
 
153
224
  *Hartley McGuire*
154
225
 
155
- * Fix the `number_to_human_size` view helper to correctly work with negative numbers.
226
+ * Introduce `relative_time_in_words` helper
156
227
 
157
- *Earlopain*
228
+ ```ruby
229
+ relative_time_in_words(3.minutes.from_now) # => "in 3 minutes"
230
+ relative_time_in_words(3.minutes.ago) # => "3 minutes ago"
231
+ relative_time_in_words(10.seconds.ago, include_seconds: true) # => "less than 10 seconds ago"
232
+ ```
233
+
234
+ *Matheus Richard*
235
+
236
+ * Make `nonce: false` remove the nonce attribute from `javascript_tag`, `javascript_include_tag`, and `stylesheet_link_tag`.
237
+
238
+ *francktrouillez*
239
+
240
+ * Add `dom_target` helper to create `dom_id`-like strings from an unlimited
241
+ number of objects.
158
242
 
159
- * Automatically discard the implicit locals injected by collection rendering for template that can't accept them.
243
+ *Ben Sheldon*
160
244
 
161
- When rendering a collection, two implicit variables are injected, which breaks templates with strict locals.
245
+ * Respect `html_options[:form]` when `collection_checkboxes` generates the
246
+ hidden `<input>`.
247
+
248
+ *Riccardo Odone*
249
+
250
+ * Layouts have access to local variables passed to `render`.
162
251
 
163
- Now they are only passed if the template will actually accept them.
252
+ This fixes #31680 which was a regression in Rails 5.1.
164
253
 
165
- *Yasha Krasnou*, *Jean Boussier*
254
+ *Mike Dalessio*
166
255
 
167
- * Fix `@rails/ujs` calling `start()` an extra time when using bundlers.
256
+ * Argument errors related to strict locals in templates now raise an
257
+ `ActionView::StrictLocalsError`, and all other argument errors are reraised as-is.
168
258
 
169
- *Hartley McGuire*, *Ryunosuke Sato*
259
+ Previously, any `ArgumentError` raised during template rendering was swallowed during strict
260
+ local error handling, so that an `ArgumentError` unrelated to strict locals (e.g., a helper
261
+ method invoked with incorrect arguments) would be replaced by a similar `ArgumentError` with an
262
+ unrelated backtrace, making it difficult to debug templates.
170
263
 
171
- * Fix the `capture` view helper compatibility with HAML and Slim.
264
+ Now, any `ArgumentError` unrelated to strict locals is reraised, preserving the original
265
+ backtrace for developers.
172
266
 
173
- When a blank string was captured in HAML or Slim (and possibly other template engines)
174
- it would instead return the entire buffer.
267
+ Also note that `ActionView::StrictLocalsError` is a subclass of `ArgumentError`, so any existing
268
+ code that rescues `ArgumentError` will continue to work.
175
269
 
176
- *Jean Boussier*
270
+ Fixes #52227.
177
271
 
178
- * Updated `@rails/ujs` files to ignore certain data-* attributes when element is contenteditable.
272
+ *Mike Dalessio*
179
273
 
180
- This fix was already landed in >= 7.0.4.3, < 7.1.0.
181
- [[CVE-2023-23913](https://github.com/advisories/GHSA-xp5h-f8jf-rc8q)]
274
+ * Improve error highlighting of multi-line methods in ERB templates or
275
+ templates where the error occurs within a do-end block.
182
276
 
183
- *Ryunosuke Sato*
277
+ *Martin Emde*
184
278
 
185
- * Added validation for HTML tag names in the `tag` and `content_tag` helper method.
279
+ * Fix a crash in ERB template error highlighting when the error occurs on a
280
+ line in the compiled template that is past the end of the source template.
186
281
 
187
- The `tag` and `content_tag` method now checks that the provided tag name adheres to the HTML
188
- specification. If an invalid HTML tag name is provided, the method raises an `ArgumentError`
189
- with an appropriate error message.
282
+ *Martin Emde*
190
283
 
191
- Examples:
284
+ * Improve reliability of ERB template error highlighting.
285
+ Fix infinite loops and crashes in highlighting and
286
+ improve tolerance for alternate ERB handlers.
192
287
 
193
- ```ruby
194
- # Raises ArgumentError: Invalid HTML5 tag name: 12p
195
- content_tag("12p") # Starting with a number
288
+ *Martin Emde*
196
289
 
197
- # Raises ArgumentError: Invalid HTML5 tag name: ""
198
- content_tag("") # Empty tag name
290
+ * Allow `hidden_field` and `hidden_field_tag` to accept a custom autocomplete value.
199
291
 
200
- # Raises ArgumentError: Invalid HTML5 tag name: div/
201
- tag("div/") # Contains a solidus
292
+ *brendon*
202
293
 
203
- # Raises ArgumentError: Invalid HTML5 tag name: "image file"
204
- tag("image file") # Contains a space
205
- ```
294
+ * Add a new configuration `content_security_policy_nonce_auto` for automatically adding a nonce to the tags affected by the directives specified by the `content_security_policy_nonce_directives` configuration option.
206
295
 
207
- *Akhil G Krishnan*
296
+ *francktrouillez*
208
297
 
209
- Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/actionview/CHANGELOG.md) for previous changes.
298
+ Please check [8-0-stable](https://github.com/rails/rails/blob/8-0-stable/actionview/CHANGELOG.md) for previous changes.
@@ -4,6 +4,7 @@ require "active_support/core_ext/module/attr_internal"
4
4
  require "active_support/core_ext/module/attribute_accessors"
5
5
  require "active_support/ordered_options"
6
6
  require "action_view/log_subscriber"
7
+ require "action_view/structured_event_subscriber"
7
8
  require "action_view/helpers"
8
9
  require "action_view/context"
9
10
  require "action_view/template"
@@ -181,6 +182,10 @@ module ActionView # :nodoc:
181
182
  class_attribute :_routes
182
183
  class_attribute :logger
183
184
 
185
+ # Specify whether to omit autocomplete="off" on hidden inputs generated by helpers.
186
+ # Configured via `config.action_view.remove_hidden_field_autocomplete`
187
+ cattr_accessor :remove_hidden_field_autocomplete, default: false
188
+
184
189
  class << self
185
190
  delegate :erb_trim_mode=, to: "ActionView::Template::Handlers::ERB"
186
191
 
@@ -242,8 +247,6 @@ module ActionView # :nodoc:
242
247
  # :startdoc:
243
248
 
244
249
  def initialize(lookup_context, assigns, controller) # :nodoc:
245
- @_config = ActiveSupport::InheritableOptions.new
246
-
247
250
  @lookup_context = lookup_context
248
251
 
249
252
  @view_renderer = ActionView::Renderer.new @lookup_context
@@ -45,7 +45,7 @@ module ActionView
45
45
  @raw_buffer << if value.html_safe?
46
46
  value
47
47
  else
48
- CGI.escapeHTML(value)
48
+ ERB::Util.unwrapped_html_escape(value)
49
49
  end
50
50
  end
51
51
  self
@@ -74,7 +74,7 @@ module ActionView
74
74
  end
75
75
 
76
76
  def dependencies
77
- render_dependencies + explicit_dependencies
77
+ WildcardResolver.new(@view_paths, render_dependencies + explicit_dependencies).resolve
78
78
  end
79
79
 
80
80
  attr_reader :name, :template
@@ -90,15 +90,15 @@ module ActionView
90
90
  end
91
91
 
92
92
  def render_dependencies
93
- render_dependencies = []
94
- render_calls = source.split(/\brender\b/).drop(1)
93
+ dependencies = []
94
+ render_calls = source.scan(/<%(?:(?:(?!<%).)*?\brender\b((?:(?!%>).)*?))%>/m).flatten
95
95
 
96
96
  render_calls.each do |arguments|
97
- add_dependencies(render_dependencies, arguments, LAYOUT_DEPENDENCY)
98
- add_dependencies(render_dependencies, arguments, RENDER_ARGUMENTS)
97
+ add_dependencies(dependencies, arguments, LAYOUT_DEPENDENCY)
98
+ add_dependencies(dependencies, arguments, RENDER_ARGUMENTS)
99
99
  end
100
100
 
101
- render_dependencies.uniq
101
+ dependencies
102
102
  end
103
103
 
104
104
  def add_dependencies(render_dependencies, arguments, pattern)
@@ -116,12 +116,37 @@ module ActionView
116
116
  end
117
117
 
118
118
  def add_static_dependency(dependencies, dependency, quote_type)
119
- if quote_type == '"'
120
- # Ignore if there is interpolation
121
- return if dependency.include?('#{')
122
- end
119
+ if quote_type == '"' && dependency.include?('#{')
120
+ scanner = StringScanner.new(dependency)
121
+
122
+ wildcard_dependency = +""
123
+
124
+ while !scanner.eos?
125
+ if scanner.scan_until(/\#{/)
126
+ unmatched_brackets = 1
127
+ wildcard_dependency << scanner.pre_match
128
+
129
+ while unmatched_brackets > 0 && !scanner.eos?
130
+ found = scanner.scan_until(/[{}]/)
131
+ return unless found
132
+
133
+ case scanner.matched
134
+ when "{"
135
+ unmatched_brackets += 1
136
+ when "}"
137
+ unmatched_brackets -= 1
138
+ end
139
+ end
140
+
141
+ wildcard_dependency << "*"
142
+ else
143
+ wildcard_dependency << scanner.rest
144
+ scanner.terminate
145
+ end
146
+ end
123
147
 
124
- if dependency
148
+ dependencies << wildcard_dependency
149
+ elsif dependency
125
150
  if dependency.include?("/")
126
151
  dependencies << dependency
127
152
  else
@@ -130,24 +155,8 @@ module ActionView
130
155
  end
131
156
  end
132
157
 
133
- def resolve_directories(wildcard_dependencies)
134
- return [] unless @view_paths
135
- return [] if wildcard_dependencies.empty?
136
-
137
- # Remove trailing "/*"
138
- prefixes = wildcard_dependencies.map { |query| query[0..-3] }
139
-
140
- @view_paths.flat_map(&:all_template_paths).uniq.filter_map { |path|
141
- path.to_s if prefixes.include?(path.prefix)
142
- }.sort
143
- end
144
-
145
158
  def explicit_dependencies
146
- dependencies = source.scan(EXPLICIT_DEPENDENCY).flatten.uniq
147
-
148
- wildcards, explicits = dependencies.partition { |dependency| dependency.end_with?("/*") }
149
-
150
- (explicits + resolve_directories(wildcards)).uniq
159
+ source.scan(EXPLICIT_DEPENDENCY).flatten.uniq
151
160
  end
152
161
  end
153
162
  end
@@ -10,7 +10,7 @@ module ActionView
10
10
  end
11
11
 
12
12
  def dependencies
13
- render_dependencies + explicit_dependencies
13
+ WildcardResolver.new(view_paths, render_dependencies + explicit_dependencies).resolve
14
14
  end
15
15
 
16
16
  def self.supports_view_paths? # :nodoc:
@@ -28,32 +28,15 @@ module ActionView
28
28
  def render_dependencies
29
29
  return [] unless template.source.include?("render")
30
30
 
31
- compiled_source = template.handler.call(template, template.source)
31
+ compiled_source = template.handler.call(template, template.encode!)
32
32
 
33
33
  @parser_class.new(@name, compiled_source).render_calls.filter_map do |render_call|
34
- next if render_call.end_with?("/_")
35
34
  render_call.gsub(%r|/_|, "/")
36
35
  end
37
36
  end
38
37
 
39
38
  def explicit_dependencies
40
- dependencies = template.source.scan(EXPLICIT_DEPENDENCY).flatten.uniq
41
-
42
- wildcards, explicits = dependencies.partition { |dependency| dependency.end_with?("/*") }
43
-
44
- (explicits + resolve_directories(wildcards)).uniq
45
- end
46
-
47
- def resolve_directories(wildcard_dependencies)
48
- return [] unless view_paths
49
- return [] if wildcard_dependencies.empty?
50
-
51
- # Remove trailing "/*"
52
- prefixes = wildcard_dependencies.map { |query| query[0..-3] }
53
-
54
- view_paths.flat_map(&:all_template_paths).uniq.filter_map { |path|
55
- path.to_s if prefixes.include?(path.prefix)
56
- }.sort
39
+ template.source.scan(EXPLICIT_DEPENDENCY).flatten.uniq
57
40
  end
58
41
  end
59
42
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ class DependencyTracker # :nodoc:
5
+ class WildcardResolver # :nodoc:
6
+ def initialize(view_paths, dependencies)
7
+ @view_paths = view_paths
8
+
9
+ @wildcard_dependencies, @explicit_dependencies =
10
+ dependencies.partition { |dependency| dependency.end_with?("/*") }
11
+ end
12
+
13
+ def resolve
14
+ return explicit_dependencies.uniq if !view_paths || wildcard_dependencies.empty?
15
+
16
+ (explicit_dependencies + resolved_wildcard_dependencies).uniq
17
+ end
18
+
19
+ private
20
+ attr_reader :explicit_dependencies, :wildcard_dependencies, :view_paths
21
+
22
+ def resolved_wildcard_dependencies
23
+ # Remove trailing "/*"
24
+ prefixes = wildcard_dependencies.map { |query| query[0..-3] }
25
+
26
+ view_paths.flat_map(&:all_template_paths).uniq.filter_map { |path|
27
+ path.to_s if prefixes.include?(path.prefix)
28
+ }.sort
29
+ end
30
+ end
31
+ end
32
+ end
@@ -10,6 +10,7 @@ module ActionView
10
10
 
11
11
  autoload :ERBTracker
12
12
  autoload :RubyTracker
13
+ autoload :WildcardResolver
13
14
 
14
15
  @trackers = Concurrent::Map.new
15
16
 
@@ -35,6 +36,11 @@ module ActionView
35
36
  @trackers.delete(handler)
36
37
  end
37
38
 
38
- register_tracker :erb, ERBTracker
39
+ case ActionView.render_tracker
40
+ when :ruby
41
+ register_tracker :erb, RubyTracker
42
+ else
43
+ register_tracker :erb, ERBTracker
44
+ end
39
45
  end
40
46
  end