summaryrefslogtreecommitdiff
path: root/lib/rb
diff options
context:
space:
mode:
authorNobuaki Sukegawa <nsukeg@gmail.com>2015-10-10 01:52:13 +0900
committerRoger Meier <roger@apache.org>2015-10-11 00:18:02 +0200
commit8cd519f7a3b9436ae95049ee4299441306bdeb5c (patch)
tree1c7ac1b21749e6ad1c8d1e8e1bb28df8527d0cae /lib/rb
parent56e5b9b01b5a033306d583cd2aec07a0dda3c9f5 (diff)
downloadthrift-8cd519f7a3b9436ae95049ee4299441306bdeb5c.tar.gz
THRIFT-3374 Ruby TJSONProtocol fails to unescape string values
This closes #640
Diffstat (limited to 'lib/rb')
-rw-r--r--lib/rb/lib/thrift/protocol/json_protocol.rb2
-rw-r--r--lib/rb/spec/json_protocol_spec.rb27
2 files changed, 25 insertions, 4 deletions
diff --git a/lib/rb/lib/thrift/protocol/json_protocol.rb b/lib/rb/lib/thrift/protocol/json_protocol.rb
index 4d6186c60..2b8ac15df 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
diff --git a/lib/rb/spec/json_protocol_spec.rb b/lib/rb/spec/json_protocol_spec.rb
index 9fb6b7bfd..b6b46bff3 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