Kouhei Sutou
null+****@clear*****
Thu Aug 30 14:50:53 JST 2018
Kouhei Sutou 2018-08-30 14:50:53 +0900 (Thu, 30 Aug 2018) Revision: cc90f2caf7010f4755e7262bdb9cea42470e619f https://github.com/ranguba/groonga-client/commit/cc90f2caf7010f4755e7262bdb9cea42470e619f Message: Support JSONP Modified files: lib/groonga/client/response/base.rb test/response/test-base.rb Modified: lib/groonga/client/response/base.rb (+8 -4) =================================================================== --- lib/groonga/client/response/base.rb 2018-07-30 18:29:44 +0900 (41b74e8) +++ lib/groonga/client/response/base.rb 2018-08-30 14:50:53 +0900 (4c6993e) @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -# # Copyright (C) 2013 Haruka Yoshihara <yoshihara �� clear-code.com> -# Copyright (C) 2013-2014 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2013-2018 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -67,7 +65,13 @@ module Groonga return_code = nil case command.output_type when :json - response = JSON.parse(raw_response) + callback = command["callback"] + if callback and + /\A#{Regexp.escape(callback)}\((.+)\);\z/ =~ raw_response + response = JSON.parse($1) + else + response = JSON.parse(raw_response) + end if response.is_a?(::Array) header, body = response return_code = header[0] if header Modified: test/response/test-base.rb (+14 -1) =================================================================== --- test/response/test-base.rb 2018-07-30 18:29:44 +0900 (e0f01e5) +++ test/response/test-base.rb 2018-08-30 14:50:53 +0900 (8d544f4) @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2014-2018 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -210,4 +210,17 @@ class TestResponseBase < Test::Unit::TestCase end end end + + class TestParse < self + def test_jsonp + command = Groonga::Command::Base.new("status", {"callback" => "a"}) + response = [ + [0, 1396012478, 0.00050806999206543], + {"start_time" => 1396012478}, + ] + raw_response = "a(#{response.to_json});" + response = Groonga::Client::Response::Base.parse(command, raw_response) + assert_equal(1396012478, response.body["start_time"]) + end + end end -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180830/f49dae36/attachment-0001.htm