From 208b22cfc3cfdd9b53cf892f59cbba75cfad62c4 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 23 May 2024 21:03:17 +0900 Subject: [PATCH] Fix frozen string error in Ruby 3.4.0-preview1 This change fixed a frozen string error with the `--enable-frozen-string-literal` in Ruby 3.4.0-preview1. See the reproduction below (note that the Addressable gem is needed): ```sh-session $ bundle install ... $ bundle add addressable ... $ RUBYOPT='--enable-frozen-string-literal -I lib -r httpclient' bundle exec ruby -e 'p HTTPClient' /work/lib/httpclient/util.rb:71:in 'HTTPClient::Util::AddressableURI#authority': can't modify frozen String: "" (FrozenError) from /usr/local/bundle/gems/addressable-2.8.6/lib/addressable/uri.rb:2350:in 'Addressable::URI#to_s' from /usr/local/bundle/gems/addressable-2.8.6/lib/addressable/uri.rb:863:in 'Addressable::URI#initialize' from /usr/local/bundle/gems/addressable-2.8.6/lib/addressable/uri.rb:165:in 'Class#new' from /usr/local/bundle/gems/addressable-2.8.6/lib/addressable/uri.rb:165:in 'Addressable::URI.parse' from /work/lib/httpclient/util.rb:154:in 'HTTPClient::Util.urify' from /work/lib/httpclient/http.rb:195:in '' from /work/lib/httpclient/http.rb:104:in '' from /work/lib/httpclient/http.rb:98:in '' from /work/lib/httpclient/http.rb:19:in '' from :136:in 'Kernel#require' from :136:in 'Kernel#require' from /work/lib/httpclient/session.rb:23:in '' from :136:in 'Kernel#require' from :136:in 'Kernel#require' from /work/lib/httpclient.rb:17:in '' from :136:in 'Kernel#require' from :136:in 'Kernel#require' ``` Ref https://www.ruby-lang.org/en/news/2024/05/16/ruby-3-4-0-preview1-released/ --- lib/httpclient/util.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/httpclient/util.rb b/lib/httpclient/util.rb index 6ff38016..8657949f 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 = +"" if self.userinfo != nil authority << "#{self.userinfo}@" end