aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-10-11 22:42:17 +0200
committerKim Alvefur <zash@zash.se>2018-10-11 22:42:17 +0200
commite99c680a142058b21d3bfbd61d50fa4dc63cbd17 (patch)
treee333c48dc1a8a6977683942e033940f3f7066e66
parent21e358c847273538b00b4d3c4f237a0459e92051 (diff)
downloadprosody-e99c680a142058b21d3bfbd61d50fa4dc63cbd17.tar.gz
prosody-e99c680a142058b21d3bfbd61d50fa4dc63cbd17.zip
util.serialization: Make errors fatal by default (like the previous implementation)
-rw-r--r--spec/util_serialization_spec.lua12
-rw-r--r--util/serialization.lua2
2 files changed, 12 insertions, 2 deletions
diff --git a/spec/util_serialization_spec.lua b/spec/util_serialization_spec.lua
index f50bdf23..180a2135 100644
--- a/spec/util_serialization_spec.lua
+++ b/spec/util_serialization_spec.lua
@@ -7,9 +7,19 @@ describe("util.serialization", function ()
assert.is_string(serialization.serialize(nil));
assert.is_string(serialization.serialize(1));
assert.is_string(serialization.serialize(true));
- assert.is_string(serialization.serialize(function () end));
end);
+ it("rejects function by default", function ()
+ assert.has_error(function ()
+ serialization.serialize(function () end)
+ end);
+ end);
+
+ it("makes a string in debug mode", function ()
+ assert.is_string(serialization.serialize(function () end, "debug"));
+ end);
+
+
it("roundtrips", function ()
local function test(data)
local serialized = serialization.serialize(data);
diff --git a/util/serialization.lua b/util/serialization.lua
index 5a8eef81..628c9d33 100644
--- a/util/serialization.lua
+++ b/util/serialization.lua
@@ -103,7 +103,7 @@ local function new(opt)
opt.equals = opt.equals or "=";
end
- local fallback = opt.fatal and fatal_error or opt.fallback or default_fallback;
+ local fallback = opt.fallback or opt.fatal == false and default_fallback or fatal_error;
local function ser(v)
return (types[type(v)] or fallback)(v);