diff options
-rw-r--r-- | spec/util_dbuffer_spec.lua | 21 | ||||
-rw-r--r-- | util/dbuffer.lua | 6 |
2 files changed, 3 insertions, 24 deletions
diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua index aa31da55..83ca1823 100644 --- a/spec/util_dbuffer_spec.lua +++ b/spec/util_dbuffer_spec.lua @@ -57,27 +57,6 @@ describe("util.dbuffer", function () assert.equal(nil, b:read_until("\n")); assert.equal("and more", b:read_chunk()); end); - - it("works with multi-character sequences", function () - local b = dbuffer.new(); - b:write("hello\r\n"); - b:write("world"); - b:write("\r\n"); - b:write("\r\n\r\n"); - b:write("stuff"); - b:write("more\r\nand more"); - - assert.equal(nil, b:read_until(".")); - assert.equal(nil, b:read_until("%")); - assert.equal("hello\r\n", b:read_until("\r\n")); - assert.equal("world\r\n", b:read_until("\r\n")); - assert.equal("\r\n", b:read_until("\r\n")); - assert.equal("\r\n", b:read_until("\r\n")); - assert.equal("stu", b:read(3)); - assert.equal("ffmore\r\n", b:read_until("\r\n")); - assert.equal(nil, b:read_until("\r\n")); - assert.equal("and more", b:read_chunk()); - end); end); describe(":discard", function () diff --git a/util/dbuffer.lua b/util/dbuffer.lua index b148a4a6..3ad5fdfe 100644 --- a/util/dbuffer.lua +++ b/util/dbuffer.lua @@ -80,12 +80,12 @@ end function dbuffer_methods:read_until(char) local buffer_pos = 0; for i, chunk in self.items:items() do - local start = 1 + self.front_consumed; + local start = 1 + ((i == 1) and self.front_consumed or 0); local char_pos = chunk:find(char, start, true); if char_pos then - return self:read(buffer_pos + (char_pos - start) + #char); + return self:read(1 + buffer_pos + char_pos - start); end - buffer_pos = buffer_pos + #chunk; + buffer_pos = buffer_pos + #chunk - (start - 1); end return nil; end |