util.dbuffer: Fix :sub() not working with partially-consumed chunks (thanks Zash for test case)
authorMatthew Wild <mwild1@gmail.com>
Mon, 24 Aug 2020 16:18:13 +0100
changeset 11049 8c6bace13229
parent 11048 7b720a815519
child 11050 64713f21ff0e
util.dbuffer: Fix :sub() not working with partially-consumed chunks (thanks Zash for test case) This also appears to fix some bugs with chunk-encoded streams in net.http.parser.
spec/util_dbuffer_spec.lua
util/dbuffer.lua
--- a/spec/util_dbuffer_spec.lua	Mon Aug 24 17:07:37 2020 +0200
+++ b/spec/util_dbuffer_spec.lua	Mon Aug 24 16:18:13 2020 +0100
@@ -67,7 +67,7 @@
 			assert.equals("hello", b:sub(1, 5));
 		end);
 
-		pending("works after discard", function ()
+		it("works after discard", function ()
 			local b = dbuffer.new(256);
 			assert.truthy(b:write("foo"));
 			assert.truthy(b:write("bar"));
--- a/util/dbuffer.lua	Mon Aug 24 17:07:37 2020 +0200
+++ b/util/dbuffer.lua	Mon Aug 24 16:18:13 2020 +0100
@@ -123,7 +123,7 @@
 
 	self:collapse(j);
 
-	return self.items:peek():sub(i, j);
+	return self.items:peek():sub(self.front_consumed+1):sub(i, j);
 end
 
 function dbuffer_methods:byte(i, j)