summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-28 09:10:32 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-28 09:10:32 +0000
commit1f262b3ef4e00fe8a7e84ab524ba53deeae1a07c (patch)
treea2a876b3e2428ad749e50960e397f72dc2a3d426
parent2f12678bcfde0b5cc2628cbba316ec0b6e89d888 (diff)
* 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
-rw-r--r--ChangeLog7
-rw-r--r--lib/open-uri.rb21
2 files changed, 27 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index abe441bd8a4..db067ac0614 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Feb 28 18:07:52 2008 Tanaka Akira <akr@fsij.org>
+
+ * 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@ruby-lang.org>
* io.c (rb_io_getline_fast): scan coderange.
diff --git a/lib/open-uri.rb b/lib/open-uri.rb
index 64b78b1217a..01d8dd643f3 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.