From ea1b1ea1aa98bc9488564ef18aa4032aa1cb5536 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 8 Nov 2023 14:05:52 +0100 Subject: String#force_encoding don't clear coderange if encoding is unchanged Some code out there blind calls `force_encoding` without checking what the original encoding was, which clears the coderange uselessly. If the String is big, it can be a rather costly mistake. For instance the `rack-utf8_sanitizer` gem does this on request bodies. --- test/ruby/test_process.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'test/ruby') diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 47228d35e6..0416b20176 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -2747,6 +2747,7 @@ EOS require 'objspace' begin; obj = "a" * 12 + obj.force_encoding(Encoding::UTF_16LE) obj.force_encoding(Encoding::BINARY) assert_include(ObjectSpace.dump(obj), '"coderange":"unknown"') Process.warmup -- cgit v1.2.3