Skip to content

Commit

Permalink
Don't try to parse javascript as JSON
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasonroelofs committed Sep 27, 2013
1 parent ef79d0f commit b7d4e21
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions features/handles_multiple_formats.feature
Expand Up @@ -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"); });'
4 changes: 2 additions & 2 deletions lib/httparty/parser.rb
Expand Up @@ -42,8 +42,8 @@ class Parser
'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
}
Expand Down
4 changes: 2 additions & 2 deletions spec/httparty/request_spec.rb
Expand Up @@ -198,13 +198,13 @@

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

Expand Down

0 comments on commit b7d4e21

Please sign in to comment.