Skip to content

Commit d29d1aa

Browse files
authored
Merge pull request #471 from byroot/frozen-string-literal
Make CI pass with `--enable-frozen-string-literal`
2 parents f4ee330 + 06070a4 commit d29d1aa

File tree

13 files changed

+117
-114
lines changed

13 files changed

+117
-114
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ jobs:
2424
'3.4',
2525
'head'
2626
]
27+
ruby-opt: [""]
28+
include:
29+
- ruby-version: '3.4'
30+
ruby-opt: '--enable-frozen-string-literal --debug-frozen-string-literal'
2731

2832
steps:
2933
- uses: actions/checkout@v3
@@ -34,6 +38,4 @@ jobs:
3438
bundler-cache: true
3539
cache-version: 2
3640
- name: Run tests
37-
run: bundle exec rake --trace
38-
env:
39-
RUBYOPT: "--disable-frozen-string-literal" # Silence these warnings for now.
41+
run: bundle exec rake --trace RUBYOPT="${{ matrix.ruby-opt }}"

Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ group :development do
1212
gem 'pry'
1313
gem 'rack', '~> 2.2'
1414
gem 'rubysspi'
15-
gem 'rubyntlm'
15+
if RUBY_VERSION >= '3.2'
16+
gem 'rubyntlm', github: 'https://github.com/WinRb/rubyntlm/pull/64'
17+
else
18+
gem 'rubyntlm'
19+
end
1620
gem 'base64'
1721
gem 'rack-ntlm-test-service'
1822
gem 'logger'

bench/download.cgi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ end
1515
buf_size = 1024 * 16
1616
STDOUT.sync = true
1717
File.open(File.expand_path('10M.bin', File.dirname(__FILE__))) do |file|
18-
buf = ''
18+
buf = ''.dup
1919
while !file.read(buf_size, buf).nil?
2020
print dump_chunk(buf)
2121
end

lib/hexdump.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ def encode(str)
1111
result = []
1212
while raw = str.slice(offset, 16) and raw.length > 0
1313
# data field
14-
data = ''
14+
data = ''.dup
1515
for v in raw.unpack('N* a*')
16-
if v.kind_of? Integer
17-
data << sprintf("%08x ", v)
18-
else
19-
v.each_byte {|c| data << sprintf("%02x", c) }
20-
end
16+
if v.kind_of? Integer
17+
data << sprintf("%08x ", v)
18+
else
19+
v.each_byte {|c| data << sprintf("%02x", c) }
20+
end
2121
end
2222
# text field
2323
text = raw.tr("\000-\037\177-\377", ".")
2424
result << sprintf("%08x %-36s %s", offset, data, text)
2525
offset += 16
2626
# omit duplicate line
2727
if /^(#{regex_quote_n(raw)})+/n =~ str[offset .. -1]
28-
result << sprintf("%08x ...", offset)
29-
offset += $&.length
30-
# should print at the end
31-
if offset == str.length
32-
result << sprintf("%08x %-36s %s", offset-16, data, text)
33-
end
28+
result << sprintf("%08x ...", offset)
29+
offset += $&.length
30+
# should print at the end
31+
if offset == str.length
32+
result << sprintf("%08x %-36s %s", offset-16, data, text)
33+
end
3434
end
3535
end
3636
result

lib/httpclient.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ def do_get_block(req, proxy, conn, &block)
12401240
conn.push(res)
12411241
return res
12421242
end
1243-
content = block ? nil : ''
1243+
content = block ? nil : ''.dup
12441244
res = HTTP::Message.new_response(content, req.header)
12451245
@debug_dev << "= Request\n\n" if @debug_dev
12461246
sess = @session_manager.query(req, proxy)

lib/httpclient/http.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def content_type=(content_type)
238238
if defined?(Encoding::ASCII_8BIT)
239239
def set_body_encoding
240240
if type = self.content_type
241-
OpenURI::Meta.init(o = '')
241+
OpenURI::Meta.init(o = ''.dup)
242242
o.meta_add_field('content-type', type)
243243
@body_encoding = o.encoding
244244
end
@@ -491,7 +491,7 @@ def init_response(body = nil)
491491
# String.
492492
#
493493
# assert: @size is not nil
494-
def dump(header = '', dev = '')
494+
def dump(header = '', dev = ''.dup)
495495
if @body.is_a?(Parts)
496496
dev << header
497497
@body.parts.each do |part|
@@ -521,7 +521,7 @@ def dump(header = '', dev = '')
521521
# reason. (header is dumped to dev, too)
522522
# If no dev (the second argument) given, this method returns a dumped
523523
# String.
524-
def dump_chunked(header = '', dev = '')
524+
def dump_chunked(header = '', dev = ''.dup)
525525
dev << header
526526
if @body.is_a?(Parts)
527527
@body.parts.each do |part|
@@ -574,7 +574,7 @@ def reset_pos(io)
574574
end
575575

576576
def dump_file(io, dev, sz)
577-
buf = ''
577+
buf = ''.dup
578578
rest = sz
579579
while rest > 0
580580
n = io.read([rest, @chunk_size].min, buf)
@@ -585,7 +585,7 @@ def dump_file(io, dev, sz)
585585
end
586586

587587
def dump_chunks(io, dev)
588-
buf = ''
588+
buf = ''.dup
589589
while !io.read(@chunk_size, buf).nil?
590590
dev << dump_chunk(buf)
591591
end
@@ -954,7 +954,7 @@ def initialize # :nodoc:
954954

955955
# Dumps message (header and body) to given dev.
956956
# dev needs to respond to <<.
957-
def dump(dev = '')
957+
def dump(dev = ''.dup)
958958
str = @http_header.dump + CRLF
959959
if @http_header.chunked
960960
dev = @http_body.dump_chunked(str, dev)

lib/httpclient/session.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ def read_body_rest
950950
end
951951

952952
def empty_bin_str
953-
str = ''
953+
str = ''.dup
954954
str.force_encoding('BINARY') if str.respond_to?(:force_encoding)
955955
str
956956
end

lib/httpclient/util.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class AddressableURI < Addressable::URI
6464
# Overwrites the original definition just for one line...
6565
def authority
6666
self.host && @authority ||= (begin
67-
authority = ""
67+
authority = "".dup
6868
if self.userinfo != nil
6969
authority << "#{self.userinfo}@"
7070
end

test/test_auth.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_BASIC_auth_force
180180
c.www_auth.basic_auth.instance_eval { @scheme = "BASIC" }
181181
#
182182
c.force_basic_auth = true
183-
c.debug_dev = str = ''
183+
c.debug_dev = str = ''.dup
184184
c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
185185
assert_equal('basic_auth OK', c.get_content("http://localhost:#{serverport}/basic_auth"))
186186
assert_equal('Authorization: Basic YWRtaW46YWRtaW4='.upcase, str.split(/\r?\n/)[5].upcase)
@@ -253,7 +253,7 @@ def test_basic_auth_reuses_credentials
253253
c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
254254
assert_equal('basic_auth OK', c.get_content("http://localhost:#{serverport}/basic_auth/"))
255255
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
256-
c.debug_dev = str = ''
256+
c.debug_dev = str = ''.dup
257257
c.get_content("http://localhost:#{serverport}/basic_auth/sub/dir/")
258258
assert_match(/Authorization: Basic YWRtaW46YWRtaW4=/, str)
259259
end
@@ -269,7 +269,7 @@ def test_digest_auth_reuses_credentials
269269
c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
270270
assert_equal('digest_auth OK', c.get_content("http://localhost:#{serverport}/digest_auth/"))
271271
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
272-
c.debug_dev = str = ''
272+
c.debug_dev = str = ''.dup
273273
c.get_content("http://localhost:#{serverport}/digest_auth/sub/dir/")
274274
assert_match(/Authorization: Digest/, str)
275275
end
@@ -315,7 +315,7 @@ def test_perfer_digest
315315
c.set_auth('http://example.com/', 'admin', 'admin')
316316
c.test_loopback_http_response << "HTTP/1.0 401 Unauthorized\nWWW-Authenticate: Basic realm=\"foo\"\nWWW-Authenticate: Digest realm=\"foo\", nonce=\"nonce\", stale=false\nContent-Length: 2\n\nNG"
317317
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
318-
c.debug_dev = str = ''
318+
c.debug_dev = str = ''.dup
319319
c.get_content('http://example.com/')
320320
assert_match(/^Authorization: Digest/, str)
321321
end
@@ -331,7 +331,7 @@ def test_proxy_auth
331331
c.set_proxy_auth('admin', 'admin')
332332
c.test_loopback_http_response << "HTTP/1.0 407 Unauthorized\nProxy-Authenticate: Basic realm=\"foo\"\nContent-Length: 2\n\nNG"
333333
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
334-
c.debug_dev = str = ''
334+
c.debug_dev = str = ''.dup
335335
c.get_content('http://example.com/')
336336
assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
337337
end
@@ -341,7 +341,7 @@ def test_proxy_auth_force
341341
c.set_proxy_auth('admin', 'admin')
342342
c.force_basic_auth = true
343343
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
344-
c.debug_dev = str = ''
344+
c.debug_dev = str = ''.dup
345345
c.get_content('http://example.com/')
346346
assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
347347
end
@@ -353,7 +353,7 @@ def test_proxy_auth_reuses_credentials
353353
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
354354
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
355355
c.get_content('http://www1.example.com/')
356-
c.debug_dev = str = ''
356+
c.debug_dev = str = ''.dup
357357
c.get_content('http://www2.example.com/')
358358
assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
359359
end
@@ -367,7 +367,7 @@ def test_digest_proxy_auth_loop
367367
ha1 = md5.hexdigest("admin:foo:admin")
368368
ha2 = md5.hexdigest("GET:/")
369369
response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
370-
c.debug_dev = str = ''
370+
c.debug_dev = str = ''.dup
371371
c.get_content('http://example.com/')
372372
assert_match(/Proxy-Authorization: Digest/, str)
373373
assert_match(%r"response=\"#{response}\"", str)
@@ -398,7 +398,7 @@ def test_prefer_digest_to_basic_proxy_auth
398398
ha1 = md5.hexdigest("admin:foo:admin")
399399
ha2 = md5.hexdigest("GET:/")
400400
response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
401-
c.debug_dev = str = ''
401+
c.debug_dev = str = ''.dup
402402
c.get_content('http://example.com/')
403403
assert_match(/Proxy-Authorization: Digest/, str)
404404
assert_match(%r"response=\"#{response}\"", str)
@@ -415,7 +415,7 @@ def test_digest_proxy_auth_reuses_credentials
415415
ha2 = md5.hexdigest("GET:/")
416416
response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
417417
c.get_content('http://www1.example.com/')
418-
c.debug_dev = str = ''
418+
c.debug_dev = str = ''.dup
419419
c.get_content('http://www2.example.com/')
420420
assert_match(/Proxy-Authorization: Digest/, str)
421421
assert_match(%r"response=\"#{response}\"", str)
@@ -437,19 +437,19 @@ def test_oauth
437437
c.www_auth.oauth.set_config('http://photos.example.net/', config)
438438
c.www_auth.oauth.challenge('http://photos.example.net/')
439439
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
440-
c.debug_dev = str = ''
440+
c.debug_dev = str = ''.dup
441441
c.get_content('http://photos.example.net/photos', [[:file, 'vacation.jpg'], [:size, 'original']])
442442
assert(str.index(%q(GET /photos?file=vacation.jpg&size=original)))
443443
assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
444444
#
445445
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
446-
c.debug_dev = str = ''
446+
c.debug_dev = str = ''.dup
447447
c.get_content('http://photos.example.net/photos?file=vacation.jpg&size=original')
448448
assert(str.index(%q(GET /photos?file=vacation.jpg&size=original)))
449449
assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
450450
#
451451
c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
452-
c.debug_dev = str = ''
452+
c.debug_dev = str = ''.dup
453453
c.post_content('http://photos.example.net/photos', [[:file, 'vacation.jpg'], [:size, 'original']])
454454
assert(str.index(%q(POST /photos)))
455455
assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="wPkvxykrw%2BBTdCcGqKr%2B3I%2BPsiM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
@@ -479,7 +479,7 @@ def test_negotiate_and_basic
479479
c.test_loopback_http_response << %Q(HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: NTLM TlRMTVNTUAACAAAAAAAAACgAAAABAAAAAAAAAAAAAAA=\r\nConnection: Keep-Alive\r\nContent-Length: 0\r\n\r\n)
480480
c.test_loopback_http_response << %Q(HTTP/1.0 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: 1\r\n\r\na)
481481
c.test_loopback_http_response << %Q(HTTP/1.0 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: 1\r\n\r\nb)
482-
c.debug_dev = str = ''
482+
c.debug_dev = str = ''.dup
483483
c.set_auth('http://www.example.org/', 'admin', 'admin')
484484
# Do NTLM negotiation
485485
c.get('http://www.example.org/foo')
@@ -488,7 +488,7 @@ def test_negotiate_and_basic
488488
assert_match(%r(Authorization: NTLM), str)
489489
assert_not_match(%r(Authorization: Basic), str)
490490
# ditto for other resource that is protected with NTLM
491-
c.debug_dev = str = ''
491+
c.debug_dev = str = ''.dup
492492
c.get('http://www.example.org/foo/subdir')
493493
assert_not_match(%r(Authorization: NTLM), str)
494494
assert_not_match(%r(Authorization: Basic), str)

test/test_hexdump.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
class TestHexDump < Test::Unit::TestCase
77
def test_encode
8-
str = "\032l\277\370\2429\216\236\351[{\{\262\350\274\376"
9-
str.force_encoding('BINARY') if str.respond_to?(:force_encoding)
8+
str = "\032l\277\370\2429\216\236\351[{\{\262\350\274\376".b
109
assert_equal(["00000000 1a6cbff8 a2398e9e e95b7b7b b2e8bcfe .l...9...[{{...."], HexDump.encode(str))
1110
end
1211
end if defined?(RUBY_ENGINE) && RUBY_ENGINE != "rbx" && RUBY_VERSION >= "1.9.0"

0 commit comments

Comments
 (0)