未验证 提交 f851e4a5 编写于 作者: Y Yuji Yaginuma 提交者: GitHub

Merge pull request #35269 from y-yagi/allow_to_pass_options_to_csp_meta_tag

Allow to pass options to `csp_meta_tag`
......@@ -14,9 +14,11 @@ module CspHelper
# This is used by the Rails UJS helper to create dynamically
# loaded inline <script> elements.
#
def csp_meta_tag
def csp_meta_tag(**options)
if content_security_policy?
tag("meta", name: "csp-nonce", content: content_security_policy_nonce)
options[:name] = "csp-nonce"
options[:content] = content_security_policy_nonce
tag("meta", options)
end
end
end
......
......@@ -16,6 +16,10 @@ def content_security_policy?
def test_csp_meta_tag
assert_equal "<meta name=\"csp-nonce\" content=\"iyhD0Yc0W+c=\" />", csp_meta_tag
end
def test_csp_meta_tag_with_options
assert_equal "<meta property=\"csp-nonce\" name=\"csp-nonce\" content=\"iyhD0Yc0W+c=\" />", csp_meta_tag(property: "csp-nonce")
end
end
class CspHelperWithCspDisabledTest < ActionView::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册