@@ -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.
@@ -35,15 +37,29 @@ def nonced_javascript_tag(content_or_options = {}, &block)
3537 #
3638 # Returns an html-safe script tag with the nonce attribute.
3739 def nonced_javascript_include_tag ( *args , &block )
38- javascript_include_tag ( *args , nonce : content_security_policy_nonce ( :script ) , &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.
4549 def nonced_javascript_pack_tag ( *args , &block )
46- javascript_pack_tag ( *args , nonce : content_security_policy_nonce ( :script ) , &block )
50+ opts = extract_options ( args ) . merge ( nonce : content_security_policy_nonce ( :script ) )
51+
52+ javascript_pack_tag ( *args , opts , &block )
53+ end
54+
55+ # Public: create a stylesheet Webpacker link tag using the content security policy nonce.
56+ # Instructs secure_headers to append a nonce to style-src directive.
57+ #
58+ # Returns an html-safe link tag with the nonce attribute.
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 )
4763 end
4864
4965 # Public: use the content security policy nonce for this request directly.
@@ -138,6 +154,14 @@ def nonced_tag(type, content_or_options, block)
138154 end
139155 content_tag type , content , options . merge ( nonce : content_security_policy_nonce ( type ) )
140156 end
157+
158+ def extract_options ( args )
159+ if args . last . is_a? Hash
160+ args . pop
161+ else
162+ { }
163+ end
164+ end
141165 end
142166end
143167
0 commit comments