Skip to content

Commit

Permalink
fix #73
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor authored Feb 7, 2017
1 parent fa453cc commit d9cdebd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Engine/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ public static function decodePayload($data, $binaryType = null)
return self::$err;
}

$msg = substr($data, $i + 1, $n);
$msg = substr($data, $i + 1/*, $n*/);

if ($length != strlen($msg))
/*if ($length != strlen($msg))
{
// parser error - ignoring payload
return self::$err;
}
}*/

if (isset($msg[0]))
{
Expand Down

2 comments on commit d9cdebd

@sunsonliu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不能简单的注释掉这段代码,这段代码的作用是校验请求数据是否完整的。
如果仅仅是为了支持中文的话可以修改成下面的样子:
image

@walkor
Copy link
Owner Author

@walkor walkor commented on d9cdebd Feb 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,只有在降级到polling的时候才会走到这个逻辑,websocket不会走到这里,所以这里的更改不会影响基于websocket通讯。polling的时候能保证每次发送的是单独的一个完整的包,不会多个请求拼接在一起的情况(不过不清楚socket.io客户端是否有其它设置允许多个包拼接一起发送给服务端),所以不会有问题。

对,原来bug是用substr截取后json不完整,因为客户端认为一个中文长度是1,但是substr认为是3,导致发中文时服务端无法解析。
看起来用mb_substr是个稳妥的方案,
但是客户端传来的中文是utf8.js转换过的中文,
还得测试下mb_substr是否能真的截取出完整的json数据(完整的请求数据)来,如果截取的不是一个完整的json那么会有问题。

Please sign in to comment.