Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rb/lib/thrift/protocol/json_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def read_json_string(skipContext = false)
# 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
Expand Down
27 changes: 24 additions & 3 deletions lib/rb/spec/json_protocol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,36 @@
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
Expand Down
11 changes: 10 additions & 1 deletion test/rb/integration/TestClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ def test_void

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
Expand Down