# HG changeset patch # User Kim Alvefur # Date 1602530960 -7200 # Node ID 3a72cb126d6c2cd332d69a07d126ce0da995063f # Parent 8d692a8a8f48529b45ca6498eaca7a5c744bbc8e# Parent 413bd21ba449993a6cfc797acb0d3fa60d3cf94d Merge 0.11->trunk diff -r 8d692a8a8f48 -r 3a72cb126d6c net/websocket/frames.lua --- a/net/websocket/frames.lua Mon Oct 12 18:27:42 2020 +0200 +++ b/net/websocket/frames.lua Mon Oct 12 21:29:20 2020 +0200 @@ -75,7 +75,7 @@ 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 @@ 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 @@ 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 -r 8d692a8a8f48 -r 3a72cb126d6c spec/util_dbuffer_spec.lua --- a/spec/util_dbuffer_spec.lua Mon Oct 12 18:27:42 2020 +0200 +++ b/spec/util_dbuffer_spec.lua Mon Oct 12 21:29:20 2020 +0200 @@ -42,6 +42,7 @@ 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 -r 8d692a8a8f48 -r 3a72cb126d6c util/dbuffer.lua --- a/util/dbuffer.lua Mon Oct 12 18:27:42 2020 +0200 +++ b/util/dbuffer.lua Mon Oct 12 21:29:20 2020 +0200 @@ -135,6 +135,7 @@ 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)