Permalink
Browse files

Merge branch 'jeremyevans-patch-1'

  • Loading branch information...
2 parents dc86dce + af855a5 commit cedac8117d5fd10e2cc6dbd501894733b0e6e3f7 @luislavena luislavena committed Jan 11, 2012
Showing with 31 additions and 1 deletion.
  1. +1 −1 lib/rubygems/specification.rb
  2. +30 −0 test/rubygems/test_gem_specification.rb
@@ -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
+ silence_warnings { 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
+ silence_warnings { Encoding.default_internal = int_enc }
+ end
+ end
+
def test_self_load_legacy_ruby
spec = Gem::Deprecate.skip_during do
eval LEGACY_RUBY_SPEC
@@ -1766,4 +1789,11 @@ def with_syck
# ignore
end
end
+
+ def silence_warnings
+ old_verbose, $VERBOSE = $VERBOSE, false
+ yield
+ ensure
+ $VERBOSE = old_verbose
+ end
end

0 comments on commit cedac81

Please sign in to comment.