diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-21 06:22:53 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-21 06:22:53 +0000 |
commit | 2cd5fca17d08c4a3b3e2fc8a31643ff2bf9ef618 (patch) | |
tree | 32969382ba20199d7811f4fed95b178d366fb363 /test/open-uri | |
parent | 74512383dd12fb950be290afaf63290f878e64d1 (diff) | |
download | ruby-2cd5fca17d08c4a3b3e2fc8a31643ff2bf9ef618.tar.gz |
lib/open-uri.rb: accept :encoding option as well as encoding in mode string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60232 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/open-uri')
-rw-r--r-- | test/open-uri/test_open-uri.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb index 49b3e3da06..3feed423a0 100644 --- a/test/open-uri/test_open-uri.rb +++ b/test/open-uri/test_open-uri.rb @@ -604,6 +604,24 @@ class TestOpenURI < Test::Unit::TestCase assert_equal(content_ej, f.read) assert_equal("text/plain", f.content_type) assert_equal("euc-jp", f.charset) + assert_equal(Encoding::EUC_JP, f.read.encoding) + } + open("#{url}/ej/", 'r:utf-8') {|f| + # override charset with encoding option + assert_equal(content_ej.dup.force_encoding('utf-8'), f.read) + assert_equal("text/plain", f.content_type) + assert_equal("euc-jp", f.charset) + assert_equal(Encoding::UTF_8, f.read.encoding) + } + open("#{url}/ej/", :encoding=>'utf-8') {|f| + # override charset with encoding option + assert_equal(content_ej.dup.force_encoding('utf-8'), f.read) + assert_equal("text/plain", f.content_type) + assert_equal("euc-jp", f.charset) + assert_equal(Encoding::UTF_8, f.read.encoding) + } + assert_raise(ArgumentError) { + open("#{url}/ej/", 'r:utf-8', :encoding=>'utf-8') {|f| } } open("#{url}/nc/") {|f| assert_equal("aa", f.read) |