Skip to content

Commit

Permalink
fix for JSON-P middleware returning bad body when no callback.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmerouze authored and rtomayko committed Oct 4, 2009
1 parent f37b574 commit 975a69a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rack/contrib/jsonp.rb
Expand Up @@ -22,7 +22,7 @@ def call(env)
response = pad(request.params.delete('callback'), response)
headers['Content-Length'] = response.length.to_s
end
[status, headers, [response]]
[status, headers, response]
end

# Pads the response with the appropriate callback format according to the
Expand Down
4 changes: 2 additions & 2 deletions test/spec_rack_jsonp.rb
Expand Up @@ -11,7 +11,7 @@
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, [test_body]] }
request = Rack::MockRequest.env_for("/", :input => "foo=bar&callback=#{callback}")
body = Rack::JSONP.new(app).call(request).last
body.join.should.equal "#{callback}(#{test_body})"
body.should.equal "#{callback}(#{test_body})"
end

specify "should modify the content length to the correct value" do
Expand All @@ -25,7 +25,7 @@
end

specify "should not change anything if no callback param is provided" do
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, '{"bar":"foo"}'] }
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['{"bar":"foo"}']] }
request = Rack::MockRequest.env_for("/", :input => "foo=bar")
body = Rack::JSONP.new(app).call(request).last
body.join.should.equal '{"bar":"foo"}'
Expand Down

0 comments on commit 975a69a

Please sign in to comment.