THRIFT-2779: Always write unescaped JSON unicode string.
Client: PHP
Patch: Phongphan Phuttha
This closes #666
diff --git a/lib/php/test/Test/Thrift/Fixtures.php b/lib/php/test/Test/Thrift/Fixtures.php
index d9d487f..2c60a08 100644
--- a/lib/php/test/Test/Thrift/Fixtures.php
+++ b/lib/php/test/Test/Thrift/Fixtures.php
@@ -46,6 +46,9 @@
self::$testArgs['testString3'] =
"string that ends in double-backslash \\\\";
+ self::$testArgs['testUnicodeStringWithNonBMP'] =
+ "สวัสดี/𝒯";
+
self::$testArgs['testDouble'] = 3.1415926535898;
// TODO: add testBinary() call
diff --git a/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php b/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php
index 7ba3441..a4ca9d5 100755
--- a/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php
+++ b/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php
@@ -200,7 +200,12 @@
$actual = $this->transport->read( BUFSIZ );
$expected = TestTJSONProtocol_Fixtures::$testArgsJSON['testStringMap'];
- $this->assertEquals( $expected, $actual );
+ /*
+ * The $actual returns unescaped string.
+ * It is required to to decode then encode it again
+ * to get the expected escaped unicode.
+ */
+ $this->assertEquals( $expected, json_encode(json_decode($actual)) );
}
public function testSet_Write()
@@ -308,6 +313,18 @@
$this->assertEquals( $expected, $actual );
}
+ public function testString4_Write()
+ {
+ $args = new \ThriftTest\ThriftTest_testString_args();
+ $args->thing = Fixtures::$testArgs['testUnicodeStringWithNonBMP'];
+ $args->write( $this->protocol );
+
+ $actual = $this->transport->read( BUFSIZ );
+ $expected = TestTJSONProtocol_Fixtures::$testArgsJSON['testUnicodeStringWithNonBMP'];
+
+ $this->assertEquals( $expected, $actual );
+ }
+
public function testDouble_Read()
{
$this->transport->write(
@@ -528,6 +545,8 @@
self::$testArgsJSON['testString3'] = '{"1":{"str":"string that ends in double-backslash \\\\\\\\"}}';
+ self::$testArgsJSON['testUnicodeStringWithNonBMP'] = '{"1":{"str":"สวัสดี\/𝒯"}}';
+
self::$testArgsJSON['testDouble'] = '{"1":{"dbl":3.1415926535898}}';
self::$testArgsJSON['testByte'] = '{"1":{"i8":1}}';