summaryrefslogtreecommitdiff
path: root/lib/open-uri.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/open-uri.rb')
-rw-r--r--lib/open-uri.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/open-uri.rb b/lib/open-uri.rb
index c68aee6e97..03f5e6de4e 100644
--- a/lib/open-uri.rb
+++ b/lib/open-uri.rb
@@ -132,6 +132,11 @@ module OpenURI
options ||= {}
OpenURI.check_options(options)
+ if /\Arb?(?:\Z|:([^:]+))/ =~ mode
+ encoding, = $1,Encoding.find($1) if $1
+ mode = nil
+ end
+
unless mode == nil ||
mode == 'r' || mode == 'rb' ||
mode == File::RDONLY
@@ -139,6 +144,8 @@ module OpenURI
end
io = open_loop(uri, options)
+ io.set_encoding(encoding) if encoding
+ p [encoding, io.external_encoding]
if block_given?
begin
yield io