@@ -19,7 +19,9 @@ def nonced_style_tag(content_or_options = {}, &block)
1919 #
2020 # Returns an html-safe link tag with the nonce attribute.
2121 def nonced_stylesheet_link_tag ( *args , &block )
22- stylesheet_link_tag ( *args , nonce : content_security_policy_nonce ( :style ) , &block )
22+ opts = extract_options ( args ) . merge ( nonce : content_security_policy_nonce ( :style ) )
23+
24+ stylesheet_link_tag ( *args , opts , &block )
2325 end
2426
2527 # Public: create a script tag using the content security policy nonce.
@@ -34,24 +36,30 @@ def nonced_javascript_tag(content_or_options = {}, &block)
3436 # Instructs secure_headers to append a nonce to script-src directive.
3537 #
3638 # Returns an html-safe script tag with the nonce attribute.
37- def nonced_javascript_include_tag ( *args , **kwargs , &block )
38- javascript_include_tag ( *args , kwargs . merge ( nonce : content_security_policy_nonce ( :script ) ) , &block )
39+ def nonced_javascript_include_tag ( *args , &block )
40+ opts = extract_options ( args ) . merge ( nonce : content_security_policy_nonce ( :script ) )
41+
42+ javascript_include_tag ( *args , opts , &block )
3943 end
4044
4145 # Public: create a script Webpacker pack tag using the content security policy nonce.
4246 # Instructs secure_headers to append a nonce to script-src directive.
4347 #
4448 # Returns an html-safe script tag with the nonce attribute.
45- def nonced_javascript_pack_tag ( *args , **kwargs , &block )
46- javascript_pack_tag ( *args , kwargs . merge ( nonce : content_security_policy_nonce ( :script ) ) , &block )
49+ def nonced_javascript_pack_tag ( *args , &block )
50+ opts = extract_options ( args ) . merge ( nonce : content_security_policy_nonce ( :script ) )
51+
52+ javascript_pack_tag ( *args , opts , &block )
4753 end
4854
4955 # Public: create a stylesheet Webpacker link tag using the content security policy nonce.
5056 # Instructs secure_headers to append a nonce to style-src directive.
5157 #
5258 # Returns an html-safe link tag with the nonce attribute.
53- def nonced_stylesheet_pack_tag ( *args , **kwargs , &block )
54- stylesheet_pack_tag ( *args , kwargs . merge ( nonce : content_security_policy_nonce ( :style ) ) , &block )
59+ def nonced_stylesheet_pack_tag ( *args , &block )
60+ opts = extract_options ( args ) . merge ( nonce : content_security_policy_nonce ( :style ) )
61+
62+ stylesheet_pack_tag ( *args , opts , &block )
5563 end
5664
5765 # Public: use the content security policy nonce for this request directly.
@@ -146,6 +154,14 @@ def nonced_tag(type, content_or_options, block)
146154 end
147155 content_tag type , content , options . merge ( nonce : content_security_policy_nonce ( type ) )
148156 end
157+
158+ def extract_options ( args )
159+ if args . last . is_a? Hash
160+ args . pop
161+ else
162+ { }
163+ end
164+ end
149165 end
150166end
151167
0 commit comments