aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-10-12 21:29:20 +0200
committerKim Alvefur <zash@zash.se>2020-10-12 21:29:20 +0200
commitab1977f889c6a1f8898cca4119d315c1c71a3b0e (patch)
treee4d006dc4649263aa45d6fb1ce4103abfc20a1e3
parentfdb82bc5938bcd60b7578ed112b40166c237cbc9 (diff)
parent0e8366644db4f804a4ad2bf80959a6140da1b504 (diff)
downloadprosody-ab1977f889c6a1f8898cca4119d315c1c71a3b0e.tar.gz
prosody-ab1977f889c6a1f8898cca4119d315c1c71a3b0e.zip
Merge 0.11->trunk
-rw-r--r--net/websocket/frames.lua6
-rw-r--r--spec/util_dbuffer_spec.lua1
-rw-r--r--util/dbuffer.lua1
3 files changed, 5 insertions, 3 deletions
diff --git a/net/websocket/frames.lua b/net/websocket/frames.lua
index a0f3bd89..922a2fce 100644
--- a/net/websocket/frames.lua
+++ b/net/websocket/frames.lua
@@ -75,7 +75,7 @@ if s_unpack then
end
local function parse_frame_header(frame)
- if #frame < 2 then return; end
+ if frame:len() < 2 then return; end
local byte1, byte2 = frame:byte(1, 2);
local result = {
@@ -97,7 +97,7 @@ local function parse_frame_header(frame)
end
local header_length = 2 + length_bytes + (result.MASK and 4 or 0);
- if #frame < header_length then return; end
+ if frame:len() < header_length then return; end
if length_bytes == 2 then
result.length = read_uint16be(frame, 3);
@@ -140,7 +140,7 @@ end
local function parse_frame(frame)
local result, pos = parse_frame_header(frame);
- if result == nil or #frame < (pos + result.length) then return nil, nil, result; end
+ if result == nil or frame:len() < (pos + result.length) then return nil, nil, result; end
result.data = parse_frame_body(frame, result, pos+1);
return result, pos + result.length;
end
diff --git a/spec/util_dbuffer_spec.lua b/spec/util_dbuffer_spec.lua
index af404042..2b1af835 100644
--- a/spec/util_dbuffer_spec.lua
+++ b/spec/util_dbuffer_spec.lua
@@ -42,6 +42,7 @@ describe("util.dbuffer", function ()
assert.truthy(b:write("hello world"));
assert.truthy(b:discard(6));
assert.equal(5, b:length());
+ assert.equal(5, b:len());
assert.equal("world", b:read(5));
end);
end);
diff --git a/util/dbuffer.lua b/util/dbuffer.lua
index a50f3a64..9d58b306 100644
--- a/util/dbuffer.lua
+++ b/util/dbuffer.lua
@@ -135,6 +135,7 @@ end
function dbuffer_methods:length()
return self._length;
end
+dbuffer_methods.len = dbuffer_methods.length; -- strings have :len()
dynamic_buffer_mt.__len = dbuffer_methods.length; -- support # operator
function dbuffer_methods:collapse(bytes)