Repository: thrift Updated Branches: refs/heads/master 56e5b9b01 -> 8cd519f7a
THRIFT-3374 Ruby TJSONProtocol fails to unescape string values This closes #640 Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/8cd519f7 Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/8cd519f7 Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/8cd519f7 Branch: refs/heads/master Commit: 8cd519f7a3b9436ae95049ee4299441306bdeb5c Parents: 56e5b9b Author: Nobuaki Sukegawa <[email protected]> Authored: Sat Oct 10 01:52:13 2015 +0900 Committer: Roger Meier <[email protected]> Committed: Sun Oct 11 00:18:02 2015 +0200 ---------------------------------------------------------------------- lib/rb/lib/thrift/protocol/json_protocol.rb | 2 +- lib/rb/spec/json_protocol_spec.rb | 27 +++++++++++++++++++++--- test/rb/integration/TestClient.rb | 11 +++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/8cd519f7/lib/rb/lib/thrift/protocol/json_protocol.rb ---------------------------------------------------------------------- diff --git a/lib/rb/lib/thrift/protocol/json_protocol.rb b/lib/rb/lib/thrift/protocol/json_protocol.rb index 4d6186c..2b8ac15 100644 --- a/lib/rb/lib/thrift/protocol/json_protocol.rb +++ b/lib/rb/lib/thrift/protocol/json_protocol.rb @@ -514,7 +514,7 @@ module Thrift # The elements of this array must match up with the sequence of characters in # escape_chars escape_char_vals = [ - '"', '\\', '/', '\b', '\f', '\n', '\r', '\t', + "\"", "\\", "\/", "\b", "\f", "\n", "\r", "\t", ] if !skipContext http://git-wip-us.apache.org/repos/asf/thrift/blob/8cd519f7/lib/rb/spec/json_protocol_spec.rb ---------------------------------------------------------------------- diff --git a/lib/rb/spec/json_protocol_spec.rb b/lib/rb/spec/json_protocol_spec.rb index 9fb6b7b..b6b46bf 100644 --- a/lib/rb/spec/json_protocol_spec.rb +++ b/lib/rb/spec/json_protocol_spec.rb @@ -293,15 +293,36 @@ describe 'JsonProtocol' do it "should read json escape char" do @trans.write('0054') @prot.read_json_escape_char.should == 'T' + + @trans.write("\"\\\"\"") + @prot.read_json_string(false).should == "\"" + + @trans.write("\"\\\\\"") + @prot.read_json_string(false).should == "\\" + + @trans.write("\"\\/\"") + @prot.read_json_string(false).should == "\/" + + @trans.write("\"\\b\"") + @prot.read_json_string(false).should == "\b" + + @trans.write("\"\\f\"") + @prot.read_json_string(false).should == "\f" + + @trans.write("\"\\n\"") + @prot.read_json_string(false).should == "\n" + + @trans.write("\"\\r\"") + @prot.read_json_string(false).should == "\r" + + @trans.write("\"\\t\"") + @prot.read_json_string(false).should == "\t" end it "should read json string" do @trans.write("\"\\P") expect {@prot.read_json_string(false)}.to raise_error(Thrift::ProtocolException) - @trans.write("\"\\n\"") - @prot.read_json_string(false).should == "\\n" - @trans.write("\"this is a test string\"") @prot.read_json_string.should == "this is a test string" end http://git-wip-us.apache.org/repos/asf/thrift/blob/8cd519f7/test/rb/integration/TestClient.rb ---------------------------------------------------------------------- diff --git a/test/rb/integration/TestClient.rb b/test/rb/integration/TestClient.rb index d04f475..8fd6336 100755 --- a/test/rb/integration/TestClient.rb +++ b/test/rb/integration/TestClient.rb @@ -89,7 +89,16 @@ class SimpleClientTest < Test::Unit::TestCase def test_string p 'test_string' - assert_equal(@client.testString('string'), 'string') + test_string = + 'quote: \" backslash:' + + ' forwardslash-escaped: \/ ' + + ' backspace: \b formfeed: \f newline: \n return: \r tab: ' + + ' now-all-of-them-together: "\\\/\b\n\r\t' + + ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><' + + ' char-to-test-json-parsing: ]] \"]] \\" }}}{ [[[ ' + + result_string = @client.testString(test_string) + assert_equal(test_string, result_string.force_encoding(Encoding::UTF_8)) end def test_bool
