From 409fa27e4628671e5fb58c1ef4906323db6c534e Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Tue, 8 Oct 2024 19:58:50 +0900 Subject: [PATCH] Address `warning: literal string will be frozen in the future` warnings 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 --- lib/httpclient.rb | 2 +- lib/httpclient/http.rb | 2 +- lib/httpclient/session.rb | 2 +- lib/httpclient/util.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/httpclient.rb b/lib/httpclient.rb index e1f18647..e844909c 100644 --- a/lib/httpclient.rb +++ b/lib/httpclient.rb @@ -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) diff --git a/lib/httpclient/http.rb b/lib/httpclient/http.rb index f6a86079..0fdedb57 100644 --- a/lib/httpclient/http.rb +++ b/lib/httpclient/http.rb @@ -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) diff --git a/lib/httpclient/session.rb b/lib/httpclient/session.rb index 67e2c3ba..8cb09d4d 100644 --- a/lib/httpclient/session.rb +++ b/lib/httpclient/session.rb @@ -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 diff --git a/lib/httpclient/util.rb b/lib/httpclient/util.rb index 6ff38016..9b93035d 100644 --- a/lib/httpclient/util.rb +++ b/lib/httpclient/util.rb @@ -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