Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove type attribute from script tag #1091

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/rollbar/middleware/js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,9 @@ def js_snippet
def script_tag(content, env)
nonce = rails5_nonce(env) || secure_headers_nonce(env)
script_tag_content = if nonce
"\n<script type=\"text/javascript\" " \
"nonce=\"#{nonce}\">#{content}</script>"
"\n<script nonce=\"#{nonce}\">#{content}</script>"
else
"\n<script type=\"text/javascript\">#{content}</script>"
"\n<script>#{content}</script>"
end

html_safe_if_needed(script_tag_content)
Expand Down
14 changes: 7 additions & 7 deletions spec/rollbar/middleware/js_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
new_body = response.body.join

expect(new_body)
.to include('<script type="text/javascript" nonce="lorem-ipsum-nonce">')
.to include('<script nonce="lorem-ipsum-nonce">')
expect(new_body).to include("var _rollbarConfig = #{json_options};")
expect(new_body).to include(snippet)
end
Expand All @@ -27,7 +27,7 @@
_, _, response = subject.call(env)
new_body = response.body.join

expect(new_body).to include('<script type="text/javascript">')
expect(new_body).to include('<script>')
expect(new_body).to include("var _rollbarConfig = #{json_options};")
expect(new_body).to include(snippet)
end
Expand All @@ -48,7 +48,7 @@
<html>
<head>
<link rel="stylesheet" href="url" type="text/css" media="screen" />
<script type="text/javascript" src="foo"></script>
<script src="foo"></script>
</head>
<body>
<h1>Testing the middleware</h1>
Expand All @@ -60,7 +60,7 @@
<<-HTML
<html>
<head><link rel="stylesheet" href="url" type="text/css" media="screen" />
<script type="text/javascript" src="foo"></script>
<script src="foo"></script>
</head>
<body>
<h1>Testing the middleware</h1>
Expand All @@ -74,7 +74,7 @@
<head>
<meta charset="UTF-8"/>
<link rel="stylesheet" href="url" type="text/css" media="screen" />
<script type="text/javascript" src="foo"></script>
<script src="foo"></script>
</head>
<body>
<h1>Testing the middleware</h1>
Expand All @@ -89,7 +89,7 @@
<meta content="origin" id="mref" name="referrer">
<link rel="stylesheet" href="url" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="foo"></script>
<script src="foo"></script>
</head>
<body>
<h1>Testing the middleware</h1>
Expand Down Expand Up @@ -262,7 +262,7 @@
_, _, response = subject.call(env)
new_body = response.body.join

expect(new_body).to include('<script type="text/javascript">')
expect(new_body).to include('<script>')
expect(new_body).to include("var _rollbarConfig = #{json_options};")
expect(new_body).to include(snippet)
end
Expand Down
28 changes: 14 additions & 14 deletions spec/rollbar/plugins/rails_js_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def reset_rails_config
get '/test_rollbar_js'

expect(response.body)
.to_not include %[<script type="text/javascript" nonce="#{nonce(response)}">]
expect(response.body).to include '<script type="text/javascript">'
.to_not include %[<script nonce="#{nonce(response)}">]
expect(response.body).to include '<script>'
end

include_examples 'adds the snippet'
Expand All @@ -163,8 +163,8 @@ def reset_rails_config
get '/test_rollbar_js'

expect(response.body)
.to_not include %[<script type="text/javascript" nonce="#{nonce(response)}">]
expect(response.body).to include '<script type="text/javascript">'
.to_not include %[<script nonce="#{nonce(response)}">]
expect(response.body).to include '<script>'
end

include_examples 'adds the snippet'
Expand All @@ -177,8 +177,8 @@ def reset_rails_config
get '/test_rollbar_js'

expect(response.body)
.to include %[<script type="text/javascript" nonce="#{nonce(response)}">]
expect(response.body).to_not include '<script type="text/javascript">'
.to include %[<script nonce="#{nonce(response)}">]
expect(response.body).to_not include '<script>'
end

include_examples 'adds the snippet'
Expand All @@ -191,8 +191,8 @@ def reset_rails_config
get '/test_rollbar_js'

expect(response.body)
.to include %[<script type="text/javascript" nonce="#{nonce(response)}">]
expect(response.body).to_not include '<script type="text/javascript">'
.to include %[<script nonce="#{nonce(response)}">]
expect(response.body).to_not include '<script>'
end

include_examples 'adds the snippet'
Expand Down Expand Up @@ -265,8 +265,8 @@ def nonce(response)
get '/test_rollbar_js'

expect(response.body)
.to_not include %[<script type="text/javascript" nonce="#{nonce(response)}">]
expect(response.body).to include '<script type="text/javascript">'
.to_not include %[<script nonce="#{nonce(response)}">]
expect(response.body).to include '<script>'
end

include_examples 'adds the snippet'
Expand All @@ -279,8 +279,8 @@ def nonce(response)
get '/test_rollbar_js_with_nonce'

expect(response.body)
.to include %[<script type="text/javascript" nonce="#{nonce(response)}">]
expect(response.body).to_not include '<script type="text/javascript">'
.to include %[<script nonce="#{nonce(response)}">]
expect(response.body).to_not include '<script>'
end

include_examples 'adds the snippet'
Expand All @@ -293,8 +293,8 @@ def nonce(response)
get '/test_rollbar_js_with_nonce'

expect(response.body)
.to include %[<script type="text/javascript" nonce="#{nonce(response)}">]
expect(response.body).to_not include '<script type="text/javascript">'
.to include %[<script nonce="#{nonce(response)}">]
expect(response.body).to_not include '<script>'
end

include_examples 'adds the snippet'
Expand Down