net.http.parser: Fix off-by-one error in chunked encoding parser
authorMatthew Wild <mwild1@gmail.com>
Mon, 15 Apr 2013 21:21:57 +0100
changeset 5475 c2c9f07c5d6a
parent 5474 11f08a27c417
child 5476 dc9485ac266b
child 5477 50cbea68586f
net.http.parser: Fix off-by-one error in chunked encoding parser
net/http/parser.lua
--- a/net/http/parser.lua	Mon Apr 15 19:37:15 2013 +0200
+++ b/net/http/parser.lua	Mon Apr 15 21:21:57 2013 +0100
@@ -133,7 +133,8 @@
 								buf = buf:gsub("^.-\r\n\r\n", ""); -- This ensure extensions and trailers are stripped
 								success_cb(packet);
 							elseif #buf - chunk_start + 2 >= chunk_size then -- we have a chunk
-								packet.body = packet.body..buf:sub(chunk_start, chunk_start + chunk_size);
+								print(chunk_start, chunk_size, ("%q"):format(buf))
+								packet.body = packet.body..buf:sub(chunk_start, chunk_start + (chunk_size-1));
 								buf = buf:sub(chunk_start + chunk_size + 2);
 								chunk_size, chunk_start = nil, nil;
 							else -- Partial chunk remaining