From 2136694a2045120af80fb7064f600a75f793720c Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Mon, 30 Dec 2013 22:04:51 +0100 Subject: [PATCH] THRIFT-2297: TJsonProtocol implementation for Delphi does not allow for both possible slash (solidus) encodings, including a test case Patch: Jens Geyer --- lib/delphi/src/Thrift.Protocol.JSON.pas | 4 ++-- lib/delphi/test/TestClient.pas | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/delphi/src/Thrift.Protocol.JSON.pas b/lib/delphi/src/Thrift.Protocol.JSON.pas index 2cc4bbd6..cce6c3cd 100644 --- a/lib/delphi/src/Thrift.Protocol.JSON.pas +++ b/lib/delphi/src/Thrift.Protocol.JSON.pas @@ -264,8 +264,8 @@ const 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 1,1,Byte('"'),1, 1,1,1,1, 1,1,1,1, 1,1,1,1); - ESCAPE_CHARS = '"\btnfr'; - ESCAPE_CHAR_VALS = '"\'#8#9#10#12#13; + ESCAPE_CHARS = '"\/btnfr'; + ESCAPE_CHAR_VALS = '"\/'#8#9#10#12#13; DEF_STRING_SIZE = 16; diff --git a/lib/delphi/test/TestClient.pas b/lib/delphi/test/TestClient.pas index e63bd4cb..0f09489a 100644 --- a/lib/delphi/test/TestClient.pas +++ b/lib/delphi/test/TestClient.pas @@ -898,6 +898,9 @@ const TEST_DOUBLE = -1.234e-56; DELTA_DOUBLE = TEST_DOUBLE * 1e-14; TEST_STRING = 'abc-'#$00E4#$00f6#$00fc; // german umlauts (en-us: "funny chars") + // test both possible solidus encodings + SOLIDUS_JSON_DATA = '"one/two\/three"'; + SOLIDUS_EXCPECTED = 'one/two/three'; begin stm := TStringStream.Create; try @@ -962,6 +965,17 @@ begin Expect( stm.Position = stm.Size, 'Stream position after read'); + // Solidus can be encoded in two ways. Make sure we can read both + stm.Position := 0; + stm.Size := 0; + stm.WriteString(SOLIDUS_JSON_DATA); + stm.Position := 0; + prot := TJSONProtocolImpl.Create( + TStreamTransportImpl.Create( + TThriftStreamAdapterDelphi.Create( stm, FALSE), nil)); + Expect( prot.ReadString = SOLIDUS_EXCPECTED, 'Solidus encoding'); + + finally stm.Free; prot := nil; //-> Release -- 2.17.1