Skip to content

Commit 5f91c40

Browse files
authored
Merge pull request #489 from petergoldstein/feature/add_ruby_3_1
Add Ruby 3.1 to the CI configuration
2 parents e6db1f8 + 57d8995 commit 5f91c40

File tree

6 files changed

+41
-35
lines changed

6 files changed

+41
-35
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
ruby: [ '2.5', '2.6', '2.7', '3.0' ]
10+
ruby: [ '2.5', '2.6', '2.7', '3.0', '3.1' ]
1111

1212
steps:
1313
- uses: actions/checkout@v2

lib/secure_headers/configuration.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ def named_append_or_override_exists?(name)
8484
def deep_copy(config)
8585
return unless config
8686
config.each_with_object({}) do |(key, value), hash|
87-
hash[key] = if value.is_a?(Array)
88-
value.dup
89-
else
90-
value
91-
end
87+
hash[key] =
88+
if value.is_a?(Array)
89+
value.dup
90+
else
91+
value
92+
end
9293
end
9394
end
9495

lib/secure_headers/headers/content_security_policy.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ class ContentSecurityPolicy
77
include PolicyManagement
88

99
def initialize(config = nil)
10-
@config = if config.is_a?(Hash)
11-
if config[:report_only]
12-
ContentSecurityPolicyReportOnlyConfig.new(config || DEFAULT_CONFIG)
10+
@config =
11+
if config.is_a?(Hash)
12+
if config[:report_only]
13+
ContentSecurityPolicyReportOnlyConfig.new(config || DEFAULT_CONFIG)
14+
else
15+
ContentSecurityPolicyConfig.new(config || DEFAULT_CONFIG)
16+
end
17+
elsif config.nil?
18+
ContentSecurityPolicyConfig.new(DEFAULT_CONFIG)
1319
else
14-
ContentSecurityPolicyConfig.new(config || DEFAULT_CONFIG)
20+
config
1521
end
16-
elsif config.nil?
17-
ContentSecurityPolicyConfig.new(DEFAULT_CONFIG)
18-
else
19-
config
20-
end
2122

2223
@preserve_schemes = @config.preserve_schemes
2324
@script_nonce = @config.script_nonce
@@ -34,11 +35,12 @@ def name
3435
##
3536
# Return the value of the CSP header
3637
def value
37-
@value ||= if @config
38-
build_value
39-
else
40-
DEFAULT_VALUE
41-
end
38+
@value ||=
39+
if @config
40+
build_value
41+
else
42+
DEFAULT_VALUE
43+
end
4244
end
4345

4446
private

lib/secure_headers/headers/policy_management.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,12 @@ def list_directive?(directive)
278278
def populate_fetch_source_with_default!(original, additions)
279279
# in case we would be appending to an empty directive, fill it with the default-src value
280280
additions.each_key do |directive|
281-
directive = if directive.to_s.end_with?("_nonce")
282-
directive.to_s.gsub(/_nonce/, "_src").to_sym
283-
else
284-
directive
285-
end
281+
directive =
282+
if directive.to_s.end_with?("_nonce")
283+
directive.to_s.gsub(/_nonce/, "_src").to_sym
284+
else
285+
directive
286+
end
286287
# Don't set a default if directive has an existing value
287288
next if original[directive]
288289
if FETCH_SOURCES.include?(directive)

lib/secure_headers/view_helper.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,13 @@ def unexpected_hash_error_message(file_path, content, hash_value)
147147

148148
def nonced_tag(type, content_or_options, block)
149149
options = {}
150-
content = if block
151-
options = content_or_options
152-
capture(&block)
153-
else
154-
content_or_options.html_safe # :'(
155-
end
150+
content =
151+
if block
152+
options = content_or_options
153+
capture(&block)
154+
else
155+
content_or_options.html_safe # :'(
156+
end
156157
content_tag type, content, options.merge(nonce: _content_security_policy_nonce(type))
157158
end
158159

spec/lib/secure_headers/view_helpers_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Message < ERB
66
include SecureHeaders::ViewHelpers
77

88
def self.template
9-
<<-TEMPLATE
9+
<<-TEMPLATE
1010
<% hashed_javascript_tag(raise_error_on_unrecognized_hash = true) do %>
1111
console.log(1)
1212
<% end %>
@@ -62,9 +62,10 @@ def capture(*args)
6262
end
6363

6464
def content_tag(type, content = nil, options = nil, &block)
65-
content = if block_given?
66-
capture(block)
67-
end
65+
content =
66+
if block_given?
67+
capture(block)
68+
end
6869

6970
if options.is_a?(Hash)
7071
options = options.map { |k, v| " #{k}=#{v}" }

0 commit comments

Comments
 (0)