Forum: Ruby-core Net::HTTP does not handle encoding correctly

Posted by lancel (lancel lancel) (Guest)
on 2012-11-22 02:51
(Received via mailing list)
Issue #2567 has been updated by lancel (lancel lancel).


=begin
All of us have read the stories of excite people's 
((<lancel|URL:http://www.lancel1.com/>))  mind, the hero of the story to 
live only for a very limited time, sometimes up to a year, sometimes as 
short as one day. But we always want to know, the doomed choose how to 
spend their ((<sac lancel|URL:http://www.lancel1.com/>)) last days. Of 
course, I say is of free men who have a choice, not whose sphere of 
activities is strictly.458gyu854
=end

----------------------------------------
Feature #2567: Net::HTTP does not handle encoding correctly
https://bugs.ruby-lang.org/issues/2567#change-33435

Author: slide_rule (Ryan Sims)
Status: Assigned
Priority: Low
Assignee: naruse (Yui NARUSE)
Category: lib
Target version: 2.0.0


=begin
 A string returned by an HTTP get does not have its encoding set 
appropriately with the charset field, nor does the content_type report 
the charset. Example code demonstrating incorrect behavior is below.

 #!/usr/bin/ruby -w
 # encoding: UTF-8

 require 'net/http'

 uri = URI.parse('http://www.hearya.com/feed/')
 result = Net::HTTP.start(uri.host, uri.port) {|http|
     http.get(uri.request_uri)
 }

 p result['content-type']     # "text/xml; charset=UTF-8" <- correct
 p result.content_type        # "text/xml" <- incorrect; truncates the 
charset field
 puts result.body.encoding    # ASCII-8BIT <- incorrect encoding, should 
be UTF-8
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.