omg-actionview 8.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +25 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.rdoc +40 -0
  5. data/app/assets/javascripts/rails-ujs.esm.js +686 -0
  6. data/app/assets/javascripts/rails-ujs.js +630 -0
  7. data/lib/action_view/base.rb +316 -0
  8. data/lib/action_view/buffers.rb +165 -0
  9. data/lib/action_view/cache_expiry.rb +69 -0
  10. data/lib/action_view/context.rb +32 -0
  11. data/lib/action_view/dependency_tracker/erb_tracker.rb +159 -0
  12. data/lib/action_view/dependency_tracker/ruby_tracker.rb +43 -0
  13. data/lib/action_view/dependency_tracker/wildcard_resolver.rb +32 -0
  14. data/lib/action_view/dependency_tracker.rb +41 -0
  15. data/lib/action_view/deprecator.rb +7 -0
  16. data/lib/action_view/digestor.rb +130 -0
  17. data/lib/action_view/flows.rb +75 -0
  18. data/lib/action_view/gem_version.rb +17 -0
  19. data/lib/action_view/helpers/active_model_helper.rb +54 -0
  20. data/lib/action_view/helpers/asset_tag_helper.rb +680 -0
  21. data/lib/action_view/helpers/asset_url_helper.rb +473 -0
  22. data/lib/action_view/helpers/atom_feed_helper.rb +205 -0
  23. data/lib/action_view/helpers/cache_helper.rb +315 -0
  24. data/lib/action_view/helpers/capture_helper.rb +236 -0
  25. data/lib/action_view/helpers/content_exfiltration_prevention_helper.rb +70 -0
  26. data/lib/action_view/helpers/controller_helper.rb +42 -0
  27. data/lib/action_view/helpers/csp_helper.rb +26 -0
  28. data/lib/action_view/helpers/csrf_helper.rb +35 -0
  29. data/lib/action_view/helpers/date_helper.rb +1266 -0
  30. data/lib/action_view/helpers/debug_helper.rb +38 -0
  31. data/lib/action_view/helpers/form_helper.rb +2765 -0
  32. data/lib/action_view/helpers/form_options_helper.rb +927 -0
  33. data/lib/action_view/helpers/form_tag_helper.rb +1088 -0
  34. data/lib/action_view/helpers/javascript_helper.rb +96 -0
  35. data/lib/action_view/helpers/number_helper.rb +165 -0
  36. data/lib/action_view/helpers/output_safety_helper.rb +70 -0
  37. data/lib/action_view/helpers/rendering_helper.rb +218 -0
  38. data/lib/action_view/helpers/sanitize_helper.rb +201 -0
  39. data/lib/action_view/helpers/tag_helper.rb +621 -0
  40. data/lib/action_view/helpers/tags/base.rb +138 -0
  41. data/lib/action_view/helpers/tags/check_box.rb +65 -0
  42. data/lib/action_view/helpers/tags/checkable.rb +18 -0
  43. data/lib/action_view/helpers/tags/collection_check_boxes.rb +37 -0
  44. data/lib/action_view/helpers/tags/collection_helpers.rb +118 -0
  45. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +31 -0
  46. data/lib/action_view/helpers/tags/collection_select.rb +33 -0
  47. data/lib/action_view/helpers/tags/color_field.rb +26 -0
  48. data/lib/action_view/helpers/tags/date_field.rb +14 -0
  49. data/lib/action_view/helpers/tags/date_select.rb +75 -0
  50. data/lib/action_view/helpers/tags/datetime_field.rb +39 -0
  51. data/lib/action_view/helpers/tags/datetime_local_field.rb +29 -0
  52. data/lib/action_view/helpers/tags/datetime_select.rb +10 -0
  53. data/lib/action_view/helpers/tags/email_field.rb +10 -0
  54. data/lib/action_view/helpers/tags/file_field.rb +26 -0
  55. data/lib/action_view/helpers/tags/grouped_collection_select.rb +34 -0
  56. data/lib/action_view/helpers/tags/hidden_field.rb +14 -0
  57. data/lib/action_view/helpers/tags/label.rb +84 -0
  58. data/lib/action_view/helpers/tags/month_field.rb +14 -0
  59. data/lib/action_view/helpers/tags/number_field.rb +20 -0
  60. data/lib/action_view/helpers/tags/password_field.rb +14 -0
  61. data/lib/action_view/helpers/tags/placeholderable.rb +24 -0
  62. data/lib/action_view/helpers/tags/radio_button.rb +32 -0
  63. data/lib/action_view/helpers/tags/range_field.rb +10 -0
  64. data/lib/action_view/helpers/tags/search_field.rb +27 -0
  65. data/lib/action_view/helpers/tags/select.rb +45 -0
  66. data/lib/action_view/helpers/tags/select_renderer.rb +56 -0
  67. data/lib/action_view/helpers/tags/tel_field.rb +10 -0
  68. data/lib/action_view/helpers/tags/text_area.rb +24 -0
  69. data/lib/action_view/helpers/tags/text_field.rb +33 -0
  70. data/lib/action_view/helpers/tags/time_field.rb +23 -0
  71. data/lib/action_view/helpers/tags/time_select.rb +10 -0
  72. data/lib/action_view/helpers/tags/time_zone_select.rb +25 -0
  73. data/lib/action_view/helpers/tags/translator.rb +39 -0
  74. data/lib/action_view/helpers/tags/url_field.rb +10 -0
  75. data/lib/action_view/helpers/tags/week_field.rb +14 -0
  76. data/lib/action_view/helpers/tags/weekday_select.rb +31 -0
  77. data/lib/action_view/helpers/tags.rb +47 -0
  78. data/lib/action_view/helpers/text_helper.rb +568 -0
  79. data/lib/action_view/helpers/translation_helper.rb +161 -0
  80. data/lib/action_view/helpers/url_helper.rb +812 -0
  81. data/lib/action_view/helpers.rb +68 -0
  82. data/lib/action_view/layouts.rb +434 -0
  83. data/lib/action_view/locale/en.yml +56 -0
  84. data/lib/action_view/log_subscriber.rb +132 -0
  85. data/lib/action_view/lookup_context.rb +299 -0
  86. data/lib/action_view/model_naming.rb +14 -0
  87. data/lib/action_view/path_registry.rb +57 -0
  88. data/lib/action_view/path_set.rb +84 -0
  89. data/lib/action_view/railtie.rb +132 -0
  90. data/lib/action_view/record_identifier.rb +118 -0
  91. data/lib/action_view/render_parser/prism_render_parser.rb +139 -0
  92. data/lib/action_view/render_parser/ripper_render_parser.rb +350 -0
  93. data/lib/action_view/render_parser.rb +40 -0
  94. data/lib/action_view/renderer/abstract_renderer.rb +186 -0
  95. data/lib/action_view/renderer/collection_renderer.rb +204 -0
  96. data/lib/action_view/renderer/object_renderer.rb +34 -0
  97. data/lib/action_view/renderer/partial_renderer/collection_caching.rb +120 -0
  98. data/lib/action_view/renderer/partial_renderer.rb +267 -0
  99. data/lib/action_view/renderer/renderer.rb +107 -0
  100. data/lib/action_view/renderer/streaming_template_renderer.rb +107 -0
  101. data/lib/action_view/renderer/template_renderer.rb +115 -0
  102. data/lib/action_view/rendering.rb +190 -0
  103. data/lib/action_view/routing_url_for.rb +149 -0
  104. data/lib/action_view/tasks/cache_digests.rake +25 -0
  105. data/lib/action_view/template/error.rb +264 -0
  106. data/lib/action_view/template/handlers/builder.rb +25 -0
  107. data/lib/action_view/template/handlers/erb/erubi.rb +85 -0
  108. data/lib/action_view/template/handlers/erb.rb +157 -0
  109. data/lib/action_view/template/handlers/html.rb +11 -0
  110. data/lib/action_view/template/handlers/raw.rb +11 -0
  111. data/lib/action_view/template/handlers.rb +66 -0
  112. data/lib/action_view/template/html.rb +33 -0
  113. data/lib/action_view/template/inline.rb +22 -0
  114. data/lib/action_view/template/raw_file.rb +25 -0
  115. data/lib/action_view/template/renderable.rb +30 -0
  116. data/lib/action_view/template/resolver.rb +212 -0
  117. data/lib/action_view/template/sources/file.rb +17 -0
  118. data/lib/action_view/template/sources.rb +13 -0
  119. data/lib/action_view/template/text.rb +32 -0
  120. data/lib/action_view/template/types.rb +50 -0
  121. data/lib/action_view/template.rb +580 -0
  122. data/lib/action_view/template_details.rb +66 -0
  123. data/lib/action_view/template_path.rb +66 -0
  124. data/lib/action_view/test_case.rb +449 -0
  125. data/lib/action_view/testing/resolvers.rb +44 -0
  126. data/lib/action_view/unbound_template.rb +67 -0
  127. data/lib/action_view/version.rb +10 -0
  128. data/lib/action_view/view_paths.rb +117 -0
  129. data/lib/action_view.rb +104 -0
  130. metadata +275 -0
@@ -0,0 +1,201 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails-html-sanitizer"
4
+
5
+ module ActionView
6
+ module Helpers # :nodoc:
7
+ # = Action View Sanitize \Helpers
8
+ #
9
+ # The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements.
10
+ # These helper methods extend Action View making them callable within your template files.
11
+ module SanitizeHelper
12
+ mattr_accessor :sanitizer_vendor, default: Rails::HTML4::Sanitizer
13
+
14
+ extend ActiveSupport::Concern
15
+
16
+ # Sanitizes HTML input, stripping all but known-safe tags and attributes.
17
+ #
18
+ # It also strips +href+ / +src+ attributes with unsafe protocols like +javascript:+, while
19
+ # also protecting against attempts to use Unicode, ASCII, and hex character references to work
20
+ # around these protocol filters.
21
+ #
22
+ # The default sanitizer is +Rails::HTML5::SafeListSanitizer+. See {Rails HTML
23
+ # Sanitizers}[https://github.com/rails/rails-html-sanitizer] for more information.
24
+ #
25
+ # Custom sanitization rules can also be provided.
26
+ #
27
+ # Please note that sanitizing user-provided text does not guarantee that the
28
+ # resulting markup is valid or even well-formed.
29
+ #
30
+ # ==== Options
31
+ #
32
+ # [+:tags+]
33
+ # An array of allowed tags.
34
+ #
35
+ # [+:attributes+]
36
+ # An array of allowed attributes.
37
+ #
38
+ # [+:scrubber+]
39
+ # A {Rails::HTML scrubber}[https://github.com/rails/rails-html-sanitizer]
40
+ # or {Loofah::Scrubber}[https://github.com/flavorjones/loofah] object that
41
+ # defines custom sanitization rules. A custom scrubber takes precedence over
42
+ # custom tags and attributes.
43
+ #
44
+ # ==== Examples
45
+ #
46
+ # ===== Normal use
47
+ #
48
+ # <%= sanitize @comment.body %>
49
+ #
50
+ # ===== Providing custom lists of permitted tags and attributes
51
+ #
52
+ # <%= sanitize @comment.body, tags: %w(strong em a), attributes: %w(href) %>
53
+ #
54
+ # ===== Providing a custom +Rails::HTML+ scrubber
55
+ #
56
+ # class CommentScrubber < Rails::HTML::PermitScrubber
57
+ # def initialize
58
+ # super
59
+ # self.tags = %w( form script comment blockquote )
60
+ # self.attributes = %w( style )
61
+ # end
62
+ #
63
+ # def skip_node?(node)
64
+ # node.text?
65
+ # end
66
+ # end
67
+ #
68
+ # <code></code>
69
+ #
70
+ # <%= sanitize @comment.body, scrubber: CommentScrubber.new %>
71
+ #
72
+ # See {Rails HTML Sanitizer}[https://github.com/rails/rails-html-sanitizer] for
73
+ # documentation about +Rails::HTML+ scrubbers.
74
+ #
75
+ # ===== Providing a custom +Loofah::Scrubber+
76
+ #
77
+ # scrubber = Loofah::Scrubber.new do |node|
78
+ # node.remove if node.name == 'script'
79
+ # end
80
+ #
81
+ # <code></code>
82
+ #
83
+ # <%= sanitize @comment.body, scrubber: scrubber %>
84
+ #
85
+ # See {Loofah's documentation}[https://github.com/flavorjones/loofah] for more
86
+ # information about defining custom +Loofah::Scrubber+ objects.
87
+ #
88
+ # ==== Global Configuration
89
+ #
90
+ # To set the default allowed tags or attributes across your application:
91
+ #
92
+ # # In config/application.rb
93
+ # config.action_view.sanitized_allowed_tags = ['strong', 'em', 'a']
94
+ # config.action_view.sanitized_allowed_attributes = ['href', 'title']
95
+ #
96
+ # The default, starting in \Rails 7.1, is to use an HTML5 parser for sanitization (if it is
97
+ # available, see NOTE below). If you wish to revert back to the previous HTML4 behavior, you
98
+ # can do so by setting the following in your application configuration:
99
+ #
100
+ # # In config/application.rb
101
+ # config.action_view.sanitizer_vendor = Rails::HTML4::Sanitizer
102
+ #
103
+ # Or, if you're upgrading from a previous version of \Rails and wish to opt into the HTML5
104
+ # behavior:
105
+ #
106
+ # # In config/application.rb
107
+ # config.action_view.sanitizer_vendor = Rails::HTML5::Sanitizer
108
+ #
109
+ # NOTE: +Rails::HTML5::Sanitizer+ is not supported on JRuby, so on JRuby platforms \Rails will
110
+ # fall back to using +Rails::HTML4::Sanitizer+.
111
+ def sanitize(html, options = {})
112
+ self.class.safe_list_sanitizer.sanitize(html, options)&.html_safe
113
+ end
114
+
115
+ # Sanitizes a block of CSS code. Used by #sanitize when it comes across a style attribute.
116
+ def sanitize_css(style)
117
+ self.class.safe_list_sanitizer.sanitize_css(style)
118
+ end
119
+
120
+ # Strips all HTML tags from +html+, including comments and special characters.
121
+ #
122
+ # strip_tags("Strip <i>these</i> tags!")
123
+ # # => Strip these tags!
124
+ #
125
+ # strip_tags("<b>Bold</b> no more! <a href='more.html'>See more here</a>...")
126
+ # # => Bold no more! See more here...
127
+ #
128
+ # strip_tags("<div id='top-bar'>Welcome to my website!</div>")
129
+ # # => Welcome to my website!
130
+ #
131
+ # strip_tags("> A quote from Smith & Wesson")
132
+ # # => &gt; A quote from Smith &amp; Wesson
133
+ def strip_tags(html)
134
+ self.class.full_sanitizer.sanitize(html)&.html_safe
135
+ end
136
+
137
+ # Strips all link tags from +html+ leaving just the link text.
138
+ #
139
+ # strip_links('<a href="http://www.rubyonrails.org">Ruby on Rails</a>')
140
+ # # => Ruby on Rails
141
+ #
142
+ # strip_links('Please e-mail me at <a href="mailto:me@email.com">me@email.com</a>.')
143
+ # # => Please e-mail me at me@email.com.
144
+ #
145
+ # strip_links('Blog: <a href="http://www.myblog.com/" class="nav" target=\"_blank\">Visit</a>.')
146
+ # # => Blog: Visit.
147
+ #
148
+ # strip_links('<<a href="https://example.org">malformed & link</a>')
149
+ # # => &lt;malformed &amp; link
150
+ def strip_links(html)
151
+ self.class.link_sanitizer.sanitize(html)
152
+ end
153
+
154
+ module ClassMethods # :nodoc:
155
+ attr_writer :full_sanitizer, :link_sanitizer, :safe_list_sanitizer
156
+
157
+ def sanitizer_vendor
158
+ ActionView::Helpers::SanitizeHelper.sanitizer_vendor
159
+ end
160
+
161
+ def sanitized_allowed_tags
162
+ sanitizer_vendor.safe_list_sanitizer.allowed_tags
163
+ end
164
+
165
+ def sanitized_allowed_attributes
166
+ sanitizer_vendor.safe_list_sanitizer.allowed_attributes
167
+ end
168
+
169
+ # Gets the Rails::HTML::FullSanitizer instance used by +strip_tags+. Replace with
170
+ # any object that responds to +sanitize+.
171
+ #
172
+ # class Application < Rails::Application
173
+ # config.action_view.full_sanitizer = MySpecialSanitizer.new
174
+ # end
175
+ def full_sanitizer
176
+ @full_sanitizer ||= sanitizer_vendor.full_sanitizer.new
177
+ end
178
+
179
+ # Gets the Rails::HTML::LinkSanitizer instance used by +strip_links+.
180
+ # Replace with any object that responds to +sanitize+.
181
+ #
182
+ # class Application < Rails::Application
183
+ # config.action_view.link_sanitizer = MySpecialSanitizer.new
184
+ # end
185
+ def link_sanitizer
186
+ @link_sanitizer ||= sanitizer_vendor.link_sanitizer.new
187
+ end
188
+
189
+ # Gets the Rails::HTML::SafeListSanitizer instance used by sanitize and +sanitize_css+.
190
+ # Replace with any object that responds to +sanitize+.
191
+ #
192
+ # class Application < Rails::Application
193
+ # config.action_view.safe_list_sanitizer = MySpecialSanitizer.new
194
+ # end
195
+ def safe_list_sanitizer
196
+ @safe_list_sanitizer ||= sanitizer_vendor.safe_list_sanitizer.new
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end