aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-01-15 21:08:01 +0100
committerKim Alvefur <zash@zash.se>2020-01-15 21:08:01 +0100
commit34098ab9da64b314b430d82b3530035670039f79 (patch)
tree7008756512c375ccd03b5c8dc892a61317e67d5f /util
parentf38173be79e56e6033ab77f5af9d35603f540ddf (diff)
downloadprosody-34098ab9da64b314b430d82b3530035670039f79.tar.gz
prosody-34098ab9da64b314b430d82b3530035670039f79.zip
util.array: Fix equality metamethod in Lua 5.3
Lua 5.2 only used the __eq metamethod if both operands have the same __eq, but Lua 5.3 will pick one from either operands that has one as long as both are tables. This results in array() == {} and all sorts of odd behavior, including array() == util.json.null. <MattJ> I think [array() == {}] should have the same semantics as {} == {}
Diffstat (limited to 'util')
-rw-r--r--util/array.lua5
1 files changed, 5 insertions, 0 deletions
diff --git a/util/array.lua b/util/array.lua
index 0b60a4fd..32d2d6a5 100644
--- a/util/array.lua
+++ b/util/array.lua
@@ -10,6 +10,7 @@ local t_insert, t_sort, t_remove, t_concat
= table.insert, table.sort, table.remove, table.concat;
local setmetatable = setmetatable;
+local getmetatable = getmetatable;
local math_random = math.random;
local math_floor = math.floor;
local pairs, ipairs = pairs, ipairs;
@@ -40,6 +41,10 @@ function array_mt.__add(a1, a2)
end
function array_mt.__eq(a, b)
+ if getmetatable(a) ~= array_mt or getmetatable(b) ~= array_mt then
+ -- Lua 5.3+ calls this if both operands are tables, even if metatables differ
+ return false;
+ end
if #a == #b then
for i = 1, #a do
if a[i] ~= b[i] then