lib/www/mechanize/page.rb in mechanize-0.9.1 vs lib/www/mechanize/page.rb in mechanize-0.9.2

- old
+ new

@@ -22,16 +22,22 @@ attr_accessor :mech attr_accessor :encoding def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil) + @encoding = nil + response.each do |header,v| + next unless v =~ /charset/i + @encoding = v.split('=').last.strip + end + @encoding ||= Util.detect_charset(body) + body = Util.to_native_charset(body, @encoding) rescue body + super(uri, response, body, code) - @encoding = Util.detect_charset(body) @mech ||= mech raise Mechanize::ContentTypeError.new(response['content-type']) unless - response['content-type'] =~ /^(text\/html)|(application\/xhtml\+xml)/ - + response['content-type'] =~ /^(text\/html)|(application\/xhtml\+xml)/i @parser = @links = @forms = @meta = @bases = @frames = @iframes = nil end def title @title ||= if parser && search('title').inner_text.length > 0