From 41b36af974908f6b2fb18c29fa467df4d5f28484 Mon Sep 17 00:00:00 2001 From: Jean byroot Boussier Date: Thu, 17 Feb 2022 16:14:34 +0100 Subject: [PATCH] Stop checking encoding names Comparing the names is much less efficient than comparing the instance directly. It may also change in the future: https://bugs.ruby-lang.org/issues/18576 --- lib/proxy_pac_rb/encoding.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/proxy_pac_rb/encoding.rb b/lib/proxy_pac_rb/encoding.rb index d047ce9..f89a63f 100644 --- a/lib/proxy_pac_rb/encoding.rb +++ b/lib/proxy_pac_rb/encoding.rb @@ -7,21 +7,21 @@ module Encoding # workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588 # workaround for rbx bug https://github.com/rubinius/rubinius/issues/1729 def encode(string) - if string.encoding.name == 'ASCII-8BIT' + if string.encoding == Encoding::BINARY data = string.dup - data.force_encoding('UTF-8') + data.force_encoding(Encoding::UTF_8) unless data.valid_encoding? raise ::Encoding::UndefinedConversionError, "Could not encode ASCII-8BIT data #{string.dump} as UTF-8" end else - data = string.encode('UTF-8') + data = string.encode(Encoding::UTF_8) end data end else def encode(string) - string.encode('UTF-8') + string.encode(Encoding::UTF_8) end end else