You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2014/12/10 20:54:58 UTC
thrift git commit: THRIFT-2779 PHP TJSONProtocol encode unicode into
UCS-4LE which can't be parsed by other langurage bindings Client: PHP Patch:
Liangliang He
Repository: thrift
Updated Branches:
refs/heads/master 40b2b64b1 -> 119869a20
THRIFT-2779 PHP TJSONProtocol encode unicode into UCS-4LE which can't be parsed by other langurage bindings
Client: PHP
Patch: Liangliang He <ll...@gmail.com>
This closes #313
This closes #244
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/119869a2
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/119869a2
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/119869a2
Branch: refs/heads/master
Commit: 119869a2041e6348027c161f144b0b3eeefb043c
Parents: 40b2b64
Author: Jens Geyer <je...@apache.org>
Authored: Wed Dec 10 20:52:07 2014 +0100
Committer: Jens Geyer <je...@apache.org>
Committed: Wed Dec 10 20:54:14 2014 +0100
----------------------------------------------------------------------
lib/php/lib/Thrift/Protocol/TJSONProtocol.php | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/119869a2/lib/php/lib/Thrift/Protocol/TJSONProtocol.php
----------------------------------------------------------------------
diff --git a/lib/php/lib/Thrift/Protocol/TJSONProtocol.php b/lib/php/lib/Thrift/Protocol/TJSONProtocol.php
index 6c93b09..dfa07d8 100644
--- a/lib/php/lib/Thrift/Protocol/TJSONProtocol.php
+++ b/lib/php/lib/Thrift/Protocol/TJSONProtocol.php
@@ -215,6 +215,15 @@ class TJSONProtocol extends TProtocol
return dechex($val);
}
+ private function json_encode_utf8($str) {
+ $str = preg_replace_callback("/\\\\u([a-f0-9]{4})/",
+ function ($matches) {
+ return iconv('UCS-4LE','UTF-8', pack('V', hexdec('U' . $matches[1])));
+ },
+ json_encode($str));
+ return preg_replace("|\\\\/|", "/", $str);
+ }
+
private function writeJSONString($b)
{
$this->context_->write();
@@ -223,7 +232,7 @@ class TJSONProtocol extends TProtocol
$this->trans_->write(self::QUOTE);
}
- $this->trans_->write(json_encode($b));
+ $this->trans_->write($this->json_encode_utf8($b));
if (is_numeric($b) && $this->context_->escapeNum()) {
$this->trans_->write(self::QUOTE);