Unbreak gem specification loading if Encoding.default_internal = 'ISO-8859-1' #146

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+24 −1
Split
@@ -900,7 +900,7 @@ def self.load file
return unless File.file?(file)
code = if defined? Encoding
- File.read file, :encoding => "UTF-8"
+ File.read file, :mode => 'r:UTF-8:-'
else
File.read file
end
@@ -308,6 +308,29 @@ def test_self_load_escape_quote
assert_equal @a2, spec
end
+ if defined?(Encoding)
+ def test_self_load_utf8_with_ascii_encoding
+ int_enc = Encoding.default_internal
+ Encoding.default_internal = 'US-ASCII'
+
+ spec2 = @a2.dup
+ bin = "\u5678"
+ spec2.authors = [bin]
+ full_path = spec2.spec_file
+ write_file full_path do |io|
+ io.write spec2.to_ruby_for_cache.force_encoding('BINARY').sub("\\u{5678}", bin.force_encoding('BINARY'))
+ end
+
+ spec = Gem::Specification.load full_path
+
+ spec2.files.clear
+
+ assert_equal spec2, spec
+ ensure
+ Encoding.default_internal = int_enc
+ end
+ end
+
def test_self_load_legacy_ruby
spec = Gem::Deprecate.skip_during do
eval LEGACY_RUBY_SPEC