aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2021-06-29 14:25:57 +0100
committerMatthew Wild <mwild1@gmail.com>2021-06-29 14:25:57 +0100
commite21e4b2b2496ffcc5d620b04cf3e01b71e9982b1 (patch)
tree8ab54137d7e92c3eea86888d47a9c38567de40f7 /util
parent4e56658eb3564a41d1014e5ee89cd01c8004252e (diff)
downloadprosody-e21e4b2b2496ffcc5d620b04cf3e01b71e9982b1.tar.gz
prosody-e21e4b2b2496ffcc5d620b04cf3e01b71e9982b1.zip
util.dbuffer: Fix bugs, remove multi-char support (more complex than first thought)
Character sequences could be split across chunk boundaries. Would require a bunch of code to make that work reliably. Only apply front_consumed on first chunk, and adjust buffer_pos accordingly.
Diffstat (limited to 'util')
-rw-r--r--util/dbuffer.lua6
1 files changed, 3 insertions, 3 deletions
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