actionview 7.1.4 → 7.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -68,6 +68,8 @@ module ActionView
68
68
  # attribute, which indicates to the browser that the script is meant to
69
69
  # be executed after the document has been parsed. Additionally, prevents
70
70
  # sending the Preload Links header.
71
+ # * <tt>:nopush</tt> - Specify if the use of server push is not desired
72
+ # for the script. Defaults to +true+.
71
73
  #
72
74
  # Any other specified options will be treated as HTML attributes for the
73
75
  # +script+ tag.
@@ -166,6 +168,10 @@ module ActionView
166
168
  # that path.
167
169
  # * <tt>:skip_pipeline</tt> - This option is used to bypass the asset pipeline
168
170
  # when it is set to true.
171
+ # * <tt>:nonce</tt> - When set to true, adds an automatic nonce value if
172
+ # you have Content Security Policy enabled.
173
+ # * <tt>:nopush</tt> - Specify if the use of server push is not desired
174
+ # for the stylesheet. Defaults to +true+.
169
175
  #
170
176
  # ==== Examples
171
177
  #
@@ -190,6 +196,9 @@ module ActionView
190
196
  # stylesheet_link_tag "random.styles", "/css/stylish"
191
197
  # # => <link href="/assets/random.styles" rel="stylesheet" />
192
198
  # # <link href="/css/stylish.css" rel="stylesheet" />
199
+ #
200
+ # stylesheet_link_tag "style", nonce: true
201
+ # # => <link href="/assets/style.css" rel="stylesheet" nonce="..." />
193
202
  def stylesheet_link_tag(*sources)
194
203
  options = sources.extract_options!.stringify_keys
195
204
  path_options = options.extract!("protocol", "extname", "host", "skip_pipeline").symbolize_keys
@@ -214,6 +223,9 @@ module ActionView
214
223
  "crossorigin" => crossorigin,
215
224
  "href" => href
216
225
  }.merge!(options)
226
+ if tag_options["nonce"] == true
227
+ tag_options["nonce"] = content_security_policy_nonce
228
+ end
217
229
 
218
230
  if apply_stylesheet_media_default && tag_options["media"].blank?
219
231
  tag_options["media"] = "screen"
@@ -351,13 +363,13 @@ module ActionView
351
363
  nopush = options.delete(:nopush) || false
352
364
  rel = mime_type == "module" ? "modulepreload" : "preload"
353
365
 
354
- link_tag = tag.link(**{
366
+ link_tag = tag.link(
355
367
  rel: rel,
356
368
  href: href,
357
369
  as: as_type,
358
370
  type: mime_type,
359
- crossorigin: crossorigin
360
- }.merge!(options.symbolize_keys))
371
+ crossorigin: crossorigin,
372
+ **options.symbolize_keys)
361
373
 
362
374
  preload_link = "<#{href}>; rel=#{rel}; as=#{as_type}"
363
375
  preload_link += "; type=#{mime_type}" if mime_type
@@ -645,11 +657,11 @@ module ActionView
645
657
  return if response_present && response.sending?
646
658
 
647
659
  if respond_to?(:request) && request
648
- request.send_early_hints("link" => preload_links.join(","))
660
+ request.send_early_hints("Link" => preload_links.join("\n"))
649
661
  end
650
662
 
651
663
  if response_present
652
- header = +response.headers["link"].to_s
664
+ header = +response.headers["Link"].to_s
653
665
  preload_links.each do |link|
654
666
  break if header.bytesize + link.bytesize > max_header_size
655
667
 
@@ -660,7 +672,7 @@ module ActionView
660
672
  end
661
673
  end
662
674
 
663
- response.headers["link"] = header
675
+ response.headers["Link"] = header
664
676
  end
665
677
  end
666
678
  end
@@ -17,7 +17,7 @@ module ActionView
17
17
  # You don't need to use these tags for regular forms as they generate their own hidden fields.
18
18
  #
19
19
  # For Ajax requests other than GETs, extract the "csrf-token" from the meta-tag and send as the
20
- # +X-CSRF-Token+ HTTP header. If you are using rails-ujs, this happens automatically.
20
+ # +X-CSRF-Token+ HTTP header.
21
21
  #
22
22
  def csrf_meta_tags
23
23
  if defined?(protect_against_forgery?) && protect_against_forgery?