1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Don't try to parse javascript as JSON

Trying to download files with the mime-type application/javascript (pure
javascript files) ends up running through the JSON parser. Javascript
code is not JSON, so this ends up throwing a MultiJSON::LoadError.
This commit is contained in:
Jason Roelofs 2013-09-27 11:56:27 -04:00
parent ef79d0fcb7
commit b7d4e21c5b
3 changed files with 12 additions and 4 deletions

View file

@ -32,3 +32,11 @@ Feature: Handles Multiple Formats
Then it should return a Hash equaling:
| key | value |
| singer | waylon jennings |
Scenario: A Javascript remote file
Given a remote service that returns '$(function() { alert("hi"); });'
And that service is accessed at the path '/service.js'
And the response from the service has a Content-Type of 'application/javascript'
When I call HTTParty#get with '/service.js'
Then it should return a String
And the return value should match '$(function() { alert("hi"); });'

View file

@ -42,8 +42,8 @@ module HTTParty
'application/xml' => :xml,
'application/json' => :json,
'text/json' => :json,
'application/javascript' => :json,
'text/javascript' => :json,
'application/javascript' => :plain,
'text/javascript' => :plain,
'text/html' => :html,
'text/plain' => :plain
}

View file

@ -198,13 +198,13 @@ describe HTTParty::Request do
it 'should handle text/javascript' do
["text/javascript", "text/javascript; charset=iso8859-1"].each do |ct|
@request.send(:format_from_mimetype, ct).should == :json
@request.send(:format_from_mimetype, ct).should == :plain
end
end
it 'should handle application/javascript' do
["application/javascript", "application/javascript; charset=iso8859-1"].each do |ct|
@request.send(:format_from_mimetype, ct).should == :json
@request.send(:format_from_mimetype, ct).should == :plain
end
end