mirror of https://github.com/nodejs/node.git
Bugfix: negative integers in raw encoding stream.
Add test. Reported by Tim Caswell.v0.7.4-release
parent
e25afc35bd
commit
9d3ed1bb92
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue