Skip to content

Commit

Permalink
Address warning: literal string will be frozen in the future warnings
Browse files Browse the repository at this point in the history
This commit addresses the `warning: literal string will be frozen in the future` warnings
appeared at Rails CI https://buildkite.com/rails/rails-nightly/builds/1122#019263a3-2200-4e62-a6a8-028cffa60aaf

Here are the warnings appeared:
```
/usr/local/lib/ruby/gems/3.4.0+0/bundler/gems/httpclient-d57cc6d5ffee/lib/httpclient.rb:1256: warning: literal string will be frozen in the future
/usr/local/lib/ruby/gems/3.4.0+0/bundler/gems/httpclient-d57cc6d5ffee/lib/httpclient/http.rb:580: warning: literal string will be frozen in the future
/usr/local/lib/ruby/gems/3.4.0+0/bundler/gems/httpclient-d57cc6d5ffee/lib/httpclient/session.rb:954: warning: literal string will be frozen in the future
/usr/local/lib/ruby/gems/3.4.0+0/bundler/gems/httpclient-d57cc6d5ffee/lib/httpclient/util.rb:71: warning: literal string will be frozen in the future
```

There should be some warnings remained because Rails CI does not use all of httpclient code. I'll open some pull requests later to address remaining ones.

Ref: https://bugs.ruby-lang.org/issues/20205
  • Loading branch information
yahonda committed Oct 11, 2024
1 parent d57cc6d commit 409fa27
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/httpclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ def do_get_block(req, proxy, conn, &block)
conn.push(res)
return res
end
content = block ? nil : ''
content = block ? nil : ''.dup
res = HTTP::Message.new_response(content, req.header)
@debug_dev << "= Request\n\n" if @debug_dev
sess = @session_manager.query(req, proxy)
Expand Down
2 changes: 1 addition & 1 deletion lib/httpclient/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def reset_pos(io)
end

def dump_file(io, dev, sz)
buf = ''
buf = ''.dup
rest = sz
while rest > 0
n = io.read([rest, @chunk_size].min, buf)
Expand Down
2 changes: 1 addition & 1 deletion lib/httpclient/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ def read_body_rest
end

def empty_bin_str
str = ''
str = ''.dup
str.force_encoding('BINARY') if str.respond_to?(:force_encoding)
str
end
Expand Down
2 changes: 1 addition & 1 deletion lib/httpclient/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AddressableURI < Addressable::URI
# Overwrites the original definition just for one line...
def authority
self.host && @authority ||= (begin
authority = ""
authority = "".dup
if self.userinfo != nil
authority << "#{self.userinfo}@"
end
Expand Down

0 comments on commit 409fa27

Please sign in to comment.