[WebSocket] Re-scoped variable
Protecting Frame::$data to prevent overflow error Correct frame contents is fetched from ::getContents()
This commit is contained in:
parent
9d2939e1e8
commit
87dcd1d510
src/Ratchet/WebSocket/Version
tests/Ratchet/Tests/WebSocket/Version/RFC6455
@ -177,7 +177,7 @@ class RFC6455 implements VersionInterface {
|
||||
* @return string
|
||||
*/
|
||||
public function frame($message, $mask = true) {
|
||||
return $this->newFrame($message)->data;
|
||||
return $this->newFrame($message)->getContents();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,23 +14,18 @@ class Connection extends AbstractConnectionDecorator {
|
||||
}
|
||||
|
||||
public function send($msg) {
|
||||
if ($msg instanceof FrameInterface) {
|
||||
$data = $msg->data;
|
||||
} else {
|
||||
$frame = new Frame($msg);
|
||||
$data = $frame->data;
|
||||
if (!($msg instanceof FrameInterface)) {
|
||||
$msg = new Frame($msg);
|
||||
}
|
||||
|
||||
$this->getConnection()->send($data);
|
||||
$this->getConnection()->send($msg->getContents());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function close($code = 1000) {
|
||||
$frame = new Frame($code, true, Frame::OP_CLOSE);
|
||||
|
||||
$this->send($frame->data);
|
||||
$this->send(new Frame($code, true, Frame::OP_CLOSE));
|
||||
|
||||
$this->getConnection()->close();
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class Frame implements FrameInterface {
|
||||
* The contents of the frame
|
||||
* @var string
|
||||
*/
|
||||
public $data = '';
|
||||
protected $data = '';
|
||||
|
||||
/**
|
||||
* Number of bytes received from the frame
|
||||
@ -367,6 +367,14 @@ class Frame implements FrameInterface {
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw contents of the frame
|
||||
* @todo This is untested, make sure the substr is right - trying to return the frame w/o the overflow
|
||||
*/
|
||||
public function getContents() {
|
||||
return substr($this->data, 0, $this->getPayloadStartingByte() + $this->getPayloadLength());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sometimes clients will concatinate more than one frame over the wire
|
||||
* This method will take the extra bytes off the end and return them
|
||||
|
@ -278,8 +278,9 @@ class FrameTest extends \PHPUnit_Framework_TestCase {
|
||||
$frame2 = Frame::create($string2);
|
||||
|
||||
$cat = new Frame;
|
||||
$cat->addBuffer($frame1->data . $frame2->data);
|
||||
$cat->addBuffer($frame1->getContents() . $frame2->getContents());
|
||||
|
||||
$this->assertEquals($frame1->getContents(), $cat->getContents());
|
||||
$this->assertEquals($string1, $cat->getPayload());
|
||||
|
||||
$uncat = new Frame;
|
||||
|
Loading…
Reference in New Issue
Block a user