lib/sup/util.rb in sup-1.1 vs lib/sup/util.rb in sup-1.2

- old
+ new

@@ -9,10 +9,11 @@ require 'enumerator' require 'benchmark' require 'unicode' require 'unicode/display_width' require 'fileutils' +require 'string-scrub' if /^2\.0\./ =~ RUBY_VERSION module ExtendedLockfile def gen_lock_id Hash[ 'host' => "#{ Socket.gethostname }", @@ -313,14 +314,11 @@ # user encoding. def fix_encoding! # first try to encode to utf-8 from whatever current encoding encode!('UTF-8', :invalid => :replace, :undef => :replace) - # do this anyway in case string is set to be UTF-8, encoding to - # something else (UTF-16 which can fully represent UTF-8) and back - # ensures invalid chars are replaced. - encode!('UTF-16', 'UTF-8', :invalid => :replace, :undef => :replace) - encode!('UTF-8', 'UTF-16', :invalid => :replace, :undef => :replace) + # ensure invalid chars are replaced + scrub! fail "Could not create valid UTF-8 string out of: '#{self.to_s}'." unless valid_encoding? # now convert to $encoding encode!($encoding, :invalid => :replace, :undef => :replace)