Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Bugfix: negative integers in raw encoding stream.
Browse files Browse the repository at this point in the history
Add test. Reported by Tim Caswell.
  • Loading branch information
ry committed Jul 31, 2009
1 parent e25afc3 commit 9d3ed1b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/net.cc
Expand Up @@ -437,7 +437,7 @@ Connection::OnReceive (const void *buf, size_t len)
// raw encoding
Local<Array> array = Array::New(len);
for (size_t i = 0; i < len; i++) {
char val = static_cast<const char*>(buf)[i];
unsigned char val = static_cast<const unsigned char*>(buf)[i];
array->Set(Integer::New(i), Integer::New(val));
}
argv[0] = array;
Expand Down
47 changes: 47 additions & 0 deletions test/mjsunit/test-tcp-raw.js
@@ -0,0 +1,47 @@
include("mjsunit.js");
PORT = 23123;

var echoServer = node.tcp.createServer(function (connection) {
connection.addListener("receive", function (chunk) {
connection.send(chunk, "raw");
});
connection.addListener("eof", function () {
connection.close();
});
});
echoServer.listen(PORT);

var recv = [];
var j = 0;

function onLoad () {
var c = node.tcp.createConnection(PORT);

c.addListener("receive", function (chunk) {
if (++j < 256) {
c.send([j], "raw");
} else {
c.close();
}
for (var i = 0; i < chunk.length; i++) {
recv.push(chunk[i]);
}
});

c.addListener("connect", function () {
c.send([j], "raw");
});

c.addListener("disconnect", function () {
p(recv);
echoServer.close();
});
};

function onExit () {
var expected = [];
for (var i = 0; i < 256; i++) {
expected.push(i);
}
assertEquals(expected, recv);
}

0 comments on commit 9d3ed1b

Please sign in to comment.