util.datamapper: Don't include empty unwrapped arrays
authorKim Alvefur <zash@zash.se>
Wed, 24 Mar 2021 00:48:02 +0100
changeset 11485 b2f9782497dd
parent 11484 0aa2971380e9
child 11486 671f6b867e0d
util.datamapper: Don't include empty unwrapped arrays Since there is no way to distinguish an empty such array from a zero-length array. Dropping it seems like the least annoying thing to do.
teal-src/util/datamapper.tl
util/datamapper.lua
--- a/teal-src/util/datamapper.tl	Wed Mar 24 00:34:22 2021 +0100
+++ b/teal-src/util/datamapper.tl	Wed Mar 24 00:48:02 2021 +0100
@@ -168,7 +168,10 @@
 						out[prop] = parse_object(propschema, c);
 					end
 				elseif proptype == "array" then
-					out[prop] = parse_array(propschema, s);
+					local a = parse_array(propschema, s);
+					if a and a[1] ~= nil then
+						out[prop] = a;
+					end
 				else
 					error "unreachable"
 				end
--- a/util/datamapper.lua	Wed Mar 24 00:34:22 2021 +0100
+++ b/util/datamapper.lua	Wed Mar 24 00:48:02 2021 +0100
@@ -138,7 +138,10 @@
 						out[prop] = parse_object(propschema, c);
 					end
 				elseif proptype == "array" then
-					out[prop] = parse_array(propschema, s);
+					local a = parse_array(propschema, s);
+					if a and a[1] ~= nil then
+						out[prop] = a;
+					end
 				else
 					error("unreachable")
 				end