From 975a69ad41c39d7edbadc72980d394e429406b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20M=C3=A9rouze?= Date: Fri, 25 Sep 2009 18:04:17 +0800 Subject: [PATCH] fix for JSON-P middleware returning bad body when no callback. --- lib/rack/contrib/jsonp.rb | 2 +- test/spec_rack_jsonp.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rack/contrib/jsonp.rb b/lib/rack/contrib/jsonp.rb index eca861b7..1f4eeee0 100644 --- a/lib/rack/contrib/jsonp.rb +++ b/lib/rack/contrib/jsonp.rb @@ -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 diff --git a/test/spec_rack_jsonp.rb b/test/spec_rack_jsonp.rb index c46342c4..3a80f81f 100644 --- a/test/spec_rack_jsonp.rb +++ b/test/spec_rack_jsonp.rb @@ -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 @@ -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"}'