Skip to content

Commit

Permalink
process charset parameter case insensitively
Browse files Browse the repository at this point in the history
  • Loading branch information
benmmurphy committed Apr 16, 2013
1 parent b18a213 commit 9c6dd9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/httparty/request.rb
Expand Up @@ -179,11 +179,11 @@ def get_charset
return nil
end

if content_type =~ /;\s*charset\s*=\s*([^=,;"\s]+)/
if content_type =~ /;\s*charset\s*=\s*([^=,;"\s]+)/i
return $1
end

if content_type =~ /;\s*charset\s*=\s*"((\\.|[^\\"])+)"/
if content_type =~ /;\s*charset\s*=\s*"((\\.|[^\\"])+)"/i
return $1.gsub(/\\(.)/, '\1')
end

Expand Down
7 changes: 7 additions & 0 deletions spec/httparty/request_spec.rb
Expand Up @@ -248,6 +248,13 @@
resp.body.encoding.should == Encoding.find("UTF-8")
end

it "should process charset in content type properly if it has a different case" do
response = stub_response "Content"
response.initialize_http_header("Content-Type" => "text/plain;CHARSET = utf-8")
resp = @request.perform
resp.body.encoding.should == Encoding.find("UTF-8")
end

it "should process quoted charset in content type properly" do
response = stub_response "Content"
response.initialize_http_header("Content-Type" => "text/plain;charset = \"utf-8\"")
Expand Down

0 comments on commit 9c6dd9b

Please sign in to comment.