ruby-changes:4140
From: ko1@a...
Date: Thu, 28 Feb 2008 18:10:51 +0900 (JST)
Subject: [ruby-changes:4140] akr - Ruby:r15630 (trunk): * lib/open-uri.rb (OpenURI::Meta#meta_setup_encoding): setup encoding
akr 2008-02-28 18:10:32 +0900 (Thu, 28 Feb 2008) New Revision: 15630 Modified files: trunk/ChangeLog trunk/lib/open-uri.rb Log: * 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. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15630&r2=15629&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/open-uri.rb?r1=15630&r2=15629&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 15629) +++ ChangeLog (revision 15630) @@ -1,3 +1,10 @@ +Thu Feb 28 18:07:52 2008 Tanaka Akira <akr@f...> + + * 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. + Thu Feb 28 15:29:12 2008 NARUSE, Yui <naruse@r...> * io.c (rb_io_getline_fast): scan coderange. Index: lib/open-uri.rb =================================================================== --- lib/open-uri.rb (revision 15629) +++ lib/open-uri.rb (revision 15630) @@ -412,8 +412,27 @@ # 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. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/