Skip to content
This repository has been archived by the owner on Sep 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #89 from perfect-solutions/master
Browse files Browse the repository at this point in the history
fix utf-8 charcaters input with multibyte internal encoding
  • Loading branch information
Devristo authored Dec 21, 2016
2 parents c130ef9 + 30c41ea commit de910b3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Devristo/Phpws/Framing/WebSocketFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,12 @@ public function encode()

public static function decode(&$buffer)
{
if(strlen($buffer) < 2)
$save_enconding = mb_internal_encoding();
mb_internal_encoding("iso-8859-1");
if(strlen($buffer) < 2) {
mb_internal_encoding($save_enconding);
return null;
}

$frame = new self();

Expand Down Expand Up @@ -166,23 +170,28 @@ public static function decode(&$buffer)
$frame->payloadLength = ($l + ($h * 0x0100000000));
$raw = substr($raw, 8);
} else{
mb_internal_encoding($save_enconding);
return null;
}

// If the frame is masked, try to eat the key from the buffer. If the buffer is insufficient, return null and
// try again next time
if ($frame->mask) {
if(strlen($raw) < 4)
if(strlen($raw) < 4) {
mb_internal_encoding($save_enconding);
return null;
}

$frame->maskingKey = substr($raw, 0, 4);
$raw = substr($raw, 4);
}


// Don't continue until we have a full frame
if(strlen($raw) < $frame->payloadLength)
if(strlen($raw) < $frame->payloadLength) {
mb_internal_encoding($save_enconding);
return null;
}

$packetPayload = substr($raw, 0, $frame->payloadLength);

Expand All @@ -194,6 +203,7 @@ public static function decode(&$buffer)
else
$frame->payloadData = $packetPayload;

mb_internal_encoding($save_enconding);
return $frame;
}

Expand Down

0 comments on commit de910b3

Please sign in to comment.