Skip to content

Commit

Permalink
fixed one-byte payload bug in Mojo::Transaction::WebSocket
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 29, 2011
1 parent e8440cf commit 7c20730
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,8 +1,9 @@
This file documents the revision history for Perl extension Mojolicious.

2.35 2011-11-29 00:00:00
2.35 2011-11-30 00:00:00
- Added EXPERIMENTAL etag method to Mojo::Headers.
- Improved documentation.
- Fixed one-byte payload bug in Mojo::Transaction::WebSocket. (tinx)

2.34 2011-11-28 00:00:00
- Added "websocket.pl" to example scripts.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -182,7 +182,7 @@ sub parse_frame {

# Check if whole packet has arrived
my $masked = vec($head, 1, 8) & 0b10000000;
return if length $clone < ($len + $hlen + $masked ? 4 : 0);
return if length $clone < ($len + $hlen + ($masked ? 4 : 0));
substr $clone, 0, $hlen, '';

# Payload
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojolicious.pm
Expand Up @@ -733,6 +733,8 @@ Anatoly Sharifulin
Andre Vieth
Andreas Jaekel
Andrew Fresh
Andreas Koenig
Expand Down
20 changes: 19 additions & 1 deletion t/mojo/websocket_frames.t
Expand Up @@ -3,7 +3,7 @@ use Mojo::Base -strict;

# "Being eaten by crocodile is just like going to sleep...
# in a giant blender."
use Test::More tests => 17;
use Test::More tests => 25;

use_ok 'Mojo::Transaction::WebSocket';

Expand Down Expand Up @@ -44,3 +44,21 @@ is $frame->[1], 2, 'binary frame';
is $frame->[2], 'just works', 'right payload';
isnt Mojo::Transaction::WebSocket->new->build_frame(1, 2, 'just works'),
$bytes, 'frames are not equal';

# One-character text frame roundtrip
$ws = Mojo::Transaction::WebSocket->new;
$bytes = $ws->build_frame(1, 1, 'a');
$frame = $ws->parse_frame(\($dummy = $bytes));
is $frame->[0], 1, 'fin flag is set';
is $frame->[1], 1, 'text frame';
is $frame->[2], 'a', 'right payload';
is $ws->build_frame(1, 1, 'a'), $bytes, 'frames are equal';

# One-byte binary frame roundtrip
$ws = Mojo::Transaction::WebSocket->new;
$bytes = $ws->build_frame(1, 2, 'a');
$frame = $ws->parse_frame(\($dummy = $bytes));
is $frame->[0], 1, 'fin flag is set';
is $frame->[1], 2, 'binary frame';
is $frame->[2], 'a', 'right payload';
is $bytes = $ws->build_frame(1, 2, 'a'), $bytes, 'frames are equal';

0 comments on commit 7c20730

Please sign in to comment.