From 08a340dbfc9208d1c0e6d574fed244a98e104f01 Mon Sep 17 00:00:00 2001 From: Edwin Mons Date: Thu, 22 Sep 2016 12:09:49 +0200 Subject: Always add a fields table member in FormConvertor The fields member of the forms generated by FormConvertor is used for lookups in the __index metafunction. If a form is parsed with no fields (and possibly no items), there wouldn't be a member 'fields', causing another __index lookup, triggering infinite recursion. There will now always be a fields array, which may be empty. Sluift/Tests/FormTest.lua has been updated to test against an empty form. Test-Information: Updated FormTest.lua works without issues. Change-Id: Idee98f23bf42e1213ca3d03707f908ed5317dad6 diff --git a/Sluift/ElementConvertors/FormConvertor.cpp b/Sluift/ElementConvertors/FormConvertor.cpp index a0e3dfe..85f40a1 100644 --- a/Sluift/ElementConvertors/FormConvertor.cpp +++ b/Sluift/ElementConvertors/FormConvertor.cpp @@ -287,9 +287,7 @@ namespace { if (!payload->getInstructions().empty()) { result["instructions"] = Lua::valueRef(payload->getInstructions()); } - if (!payload->getFields().empty()) { - result["fields"] = valueRef(convertFieldListToLua(payload->getFields())); - } + result["fields"] = valueRef(convertFieldListToLua(payload->getFields())); if (!payload->getReportedFields().empty()) { result["reported_fields"] = valueRef(convertFieldListToLua(payload->getReportedFields())); } diff --git a/Sluift/Tests/FormTest.lua b/Sluift/Tests/FormTest.lua index 8065360..d584646 100644 --- a/Sluift/Tests/FormTest.lua +++ b/Sluift/Tests/FormTest.lua @@ -1,5 +1,5 @@ --[[ - Copyright (c) 2013 Isode Limited. + Copyright (c) 2013-2016 Isode Limited. All rights reserved. See the COPYING file for more information. --]] @@ -90,3 +90,15 @@ assert(type(text_multi_field['value']) == 'table') --print(sluift.to_xml({type = 'form', data = form})) + +-- test parsing an empty form -- this had issues as reported in SWIFT-174 +empty_form = [[]] +form = sluift.from_xml(empty_form) +-- and check if we can access all fields without problems +assert(type(form._type)) +assert(type(form.title)) +assert(type(form.instructions)) +assert(type(form.type)) +assert(type(form.fields)) +assert(type(form.items)) +assert(type(form.reported_items)) -- cgit v0.10.2-6-g49f6