From 767bdc8b4e7da0513537b8872753547564670b2c Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Fri, 19 Jul 2024 23:36:14 +0900 Subject: [PATCH] Suppress Ruby 3.4's warning (#1028) Starting with Ruby 3.4, there is a gradual plan to freeze strings: https://bugs.ruby-lang.org/issues/20205#note-35 This PR suppresses the following Ruby 3.4's warning: ```console /Users/koic/.rbenv/versions/3.4-dev/lib/ruby/gems/3.4.0+0/gems/parser-3.3.4.0/lib/parser/source/buffer.rb:97: warning: literal string will be frozen in the future ``` --- lib/parser/source/buffer.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/parser/source/buffer.rb b/lib/parser/source/buffer.rb index ea9c7cf8a..e74eaaabe 100644 --- a/lib/parser/source/buffer.rb +++ b/lib/parser/source/buffer.rb @@ -94,16 +94,15 @@ def self.recognize_encoding(string) # def self.reencode_string(input) original_encoding = input.encoding - detected_encoding = recognize_encoding(input.force_encoding(Encoding::BINARY)) + dup_input = input.dup + detected_encoding = recognize_encoding(dup_input.force_encoding(Encoding::BINARY)) if detected_encoding.nil? - input.force_encoding(original_encoding) + dup_input.force_encoding(original_encoding) elsif detected_encoding == Encoding::BINARY input else - input. - force_encoding(detected_encoding). - encode(Encoding::UTF_8) + dup_input.force_encoding(detected_encoding).encode(Encoding::UTF_8) end end