diff options
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2016-07-05 08:26:23 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2016-07-05 17:21:59 +0200
commit6744da6188c8ba1c553131582e9624db50424908 (patch)
parent2ecdda76a3325ef0bd9c04f4c229708c8a8b8702 (diff)
Protocol: Relax UTF-8 checking when sending.
All messages sent with `Protocol\Rfc6455::send` must be UTF-8 encoded. This is a hard constraint. All messages received by the server must be UTF-8 encoded, so we ease the work of the server and avoid sending invalid messages by adding this constraint. This constraint was checked when the opcode was either `OPCODE_TEXT_FRAME` or `OPCODE_CONTINUATION_FRAME`. This is wrong because in some cases a valid UTF-8 message can be send byte after byte as fragments. Each fragment is not necessarily a valid UTF-8 string. So now, this constraint is checked only when the opcode is `OPCODE_TEXT_FRAME` and when the message is not fragmented (so `end` is set to `true`). And so, this is possible to send a valid UTF-8 message as many invalid UTF-8 fragments.
1 files changed, 2 insertions, 2 deletions
diff --git a/Protocol/Rfc6455.php b/Protocol/Rfc6455.php
index 13994e3..79ce5b7 100644
--- a/Protocol/Rfc6455.php
+++ b/Protocol/Rfc6455.php
@@ -317,8 +317,8 @@ class Rfc6455 extends Generic
$end = true,
$mask = false
) {
- if ((Websocket\Connection::OPCODE_TEXT_FRAME === $opcode ||
- Websocket\Connection::OPCODE_CONTINUATION_FRAME === $opcode) &&
+ if (Websocket\Connection::OPCODE_TEXT_FRAME === $opcode &&
+ true === $end &&
false === (bool) preg_match('//u', $message)) {
throw new Websocket\Exception\InvalidMessage(
'Message ā€œ%sā€ is not in UTF-8, cannot send it.',