From 1f262b3ef4e00fe8a7e84ab524ba53deeae1a07c Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 28 Feb 2008 09:10:32 +0000 Subject: * lib/open-uri.rb (OpenURI::Meta#meta_setup_encoding): setup encoding by charset. (OpenURI::Meta#meta_add_field): call meta_setup_encoding when content-type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/open-uri.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/open-uri.rb b/lib/open-uri.rb index 64b78b1217..01d8dd643f 100644 --- a/lib/open-uri.rb +++ b/lib/open-uri.rb @@ -412,8 +412,27 @@ module OpenURI # The Hash keys are downcased for canonicalization. attr_reader :meta + def meta_setup_encoding # :nodoc: + charset = self.charset + return unless charset + begin + enc = Encoding.find(charset) + rescue ArgumentError + return + end + if self.respond_to? :force_encoding + self.force_encoding(enc) + elsif self.respond_to? :string + self.string.force_encoding(enc) + else # Tempfile + self.set_encoding enc + end + end + def meta_add_field(name, value) # :nodoc: - @meta[name.downcase] = value + name = name.downcase + @meta[name] = value + meta_setup_encoding if name == 'content-type' end # returns a Time which represents Last-Modified field. -- cgit v1.2.3