Skip to content

Commit

Permalink
merge revision 25178 to release-1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
rob committed Dec 22, 2012
1 parent 1f80eb4 commit 5a9cf80
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion library/Zend/Amf/Parse/Amf0/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
case (is_bool($data)):
$markerType = Zend_Amf_Constants::AMF0_BOOLEAN;
break;
case (is_string($data) && (strlen($data) > 65536)):
case (is_string($data) && (($this->_mbStringFunctionsOverloaded ? mb_strlen($data, '8bit') : strlen($data)) > 65536)):
$markerType = Zend_Amf_Constants::AMF0_LONGSTRING;
break;
case (is_string($data)):
Expand Down
4 changes: 2 additions & 2 deletions library/Zend/Amf/Parse/Amf3/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function writeInteger($int)
* @return Zend_Amf_Parse_Amf3_Serializer
*/
protected function writeBinaryString(&$string){
$ref = strlen($string) << 1 | 0x01;
$ref = ($this->_mbStringFunctionsOverloaded ? mb_strlen($string, '8bit') : strlen($string)) << 1 | 0x01;
$this->writeInteger($ref);
$this->_stream->writeBytes($string);

Expand All @@ -230,7 +230,7 @@ protected function writeBinaryString(&$string){
*/
public function writeString(&$string)
{
$len = strlen($string);
$len = $this->_mbStringFunctionsOverloaded ? mb_strlen($string, '8bit') : strlen($string);
if(!$len){
$this->writeInteger(0x01);
return $this;
Expand Down
8 changes: 8 additions & 0 deletions library/Zend/Amf/Parse/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ abstract class Zend_Amf_Parse_Serializer
*/
protected $_stream;

/**
* str* functions overloaded using mbstring.func_overload
*
* @var bool
*/
protected $mbStringFunctionsOverloaded;

/**
* Constructor
*
Expand All @@ -46,6 +53,7 @@ abstract class Zend_Amf_Parse_Serializer
public function __construct(Zend_Amf_Parse_OutputStream $stream)
{
$this->_stream = $stream;
$this->_mbStringFunctionsOverloaded = function_exists('mb_strlen') && (ini_get('mbstring.func_overload') !== '') && ((int)ini_get('mbstring.func_overload') & 2);
}

/**
Expand Down
16 changes: 11 additions & 5 deletions library/Zend/Amf/Util/BinaryStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class Zend_Amf_Util_BinaryStream
*/
protected $_needle;

/**
* @var bool str* functions overloaded using mbstring.func_overload?
*/
protected $_mbStringFunctionsOverloaded;

/**
* Constructor
*
Expand All @@ -69,7 +74,8 @@ public function __construct($stream)

$this->_stream = $stream;
$this->_needle = 0;
$this->_streamLength = strlen($stream);
$this->_mbStringFunctionsOverloaded = function_exists('mb_strlen') && (ini_get('mbstring.func_overload') !== '') && ((int)ini_get('mbstring.func_overload') & 2);
$this->_streamLength = $this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream);
$this->_bigEndian = (pack('l', 1) === "\x00\x00\x00\x01");
}

Expand Down Expand Up @@ -97,7 +103,7 @@ public function readBytes($length)
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('Buffer underrun at needle position: ' . $this->_needle . ' while requesting length: ' . $length);
}
$bytes = substr($this->_stream, $this->_needle, $length);
$bytes = $this->_mbStringFunctionsOverloaded ? mb_substr($this->_stream, $this->_needle, $length, '8bit') : substr($this->_stream, $this->_needle, $length);
$this->_needle+= $length;
return $bytes;
}
Expand Down Expand Up @@ -184,7 +190,7 @@ public function readUtf()
*/
public function writeUtf($stream)
{
$this->writeInt(strlen($stream));
$this->writeInt($this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream));
$this->_stream.= $stream;
return $this;
}
Expand All @@ -209,7 +215,7 @@ public function readLongUtf()
*/
public function writeLongUtf($stream)
{
$this->writeLong(strlen($stream));
$this->writeLong($this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream));
$this->_stream.= $stream;
}

Expand Down Expand Up @@ -255,7 +261,7 @@ public function readUnsignedShort()
*/
public function readDouble()
{
$bytes = substr($this->_stream, $this->_needle, 8);
$bytes = $this->_mbStringFunctionsOverloaded ? mb_substr($this->_stream, $this->_needle, 8, '8bit') : substr($this->_stream, $this->_needle, 8);
$this->_needle+= 8;

if (!$this->_bigEndian) {
Expand Down

0 comments on commit 5a9cf80

Please sign in to comment.