THRIFT-2413: UTF-8 sent by PHP as JSON is not understood by TJsonProtocol
Client: Python
Patch: Phongphan Phuttha

This patch allows readJSONString to decode escaped unicode string including encoded surrogate pair.

This closes #673
diff --git a/lib/py/test/thrift_json.py b/lib/py/test/thrift_json.py
new file mode 100644
index 0000000..cef8870
--- /dev/null
+++ b/lib/py/test/thrift_json.py
@@ -0,0 +1,31 @@
+from thrift import Thrift
+from thrift.protocol.TJSONProtocol import TJSONProtocol
+from thrift.transport import TTransport
+
+import sys
+import unittest
+
+#
+# In order to run the test under Windows. We need to create symbolic link
+# name 'thrift' to '../src' folder by using:
+#
+# mklink /D thrift ..\src
+#
+
+class TestJSONString(unittest.TestCase):
+
+  def test_escaped_unicode_string(self):
+    unicode_json = '"hello \\u0e01\\u0e02\\u0e03\\ud835\\udcab unicode"'
+    unicode_text = u'hello \u0e01\u0e02\u0e03\U0001D4AB unicode'
+
+    buf = TTransport.TMemoryBuffer(unicode_json)
+    transport = TTransport.TBufferedTransportFactory().getTransport(buf)
+    protocol = TJSONProtocol(transport)
+
+    if sys.version_info[0] == 2:
+      unicode_text = unicode_text.encode('utf8')
+    self.assertEqual(protocol.readString(), unicode_text)
+
+if __name__ == '__main__':
+  unittest.main()
+