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