Skip to content

Commit

Permalink
Suppress Ruby 3.4's warning (#1028)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
koic authored Jul 19, 2024
1 parent 2aa2ba6 commit 767bdc8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/parser/source/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 767bdc8

Please sign in to comment.