Bug #2566

Net::HTTP does not handle encoding correctly

Added by Ryan Sims about 2 years ago. Updated 10 months ago.

[redmine4ruby-lang:265]
Status:Closed Start date:01/07/2010
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-

Description

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

History

Updated by Ryan Sims about 2 years ago

Sorry, posted to wrong project. Please close.

Updated by Yui NARUSE 11 months ago

  • Status changed from Open to Closed

Also available in: Atom PDF