luci-base: dispatcher: let attr() automatically serialize JSON
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 10 Feb 2016 18:30:43 +0000 (19:30 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 10 Feb 2016 18:31:10 +0000 (19:31 +0100)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
modules/luci-base/luasrc/dispatcher.lua

index 91a4c63a67fef5b185b68a1935c2d90e328f7825..c7903e6384e7a2f07f2952d352fddbf02aee9f25 100644 (file)
@@ -273,6 +273,13 @@ function dispatch(request)
                        if cond then
                                local env = getfenv(3)
                                local scope = (type(env.self) == "table") and env.self
+                               if type(val) == "table" then
+                                       if not next(val) then
+                                               return ''
+                                       else
+                                               val = util.serialize_json(val)
+                                       end
+                               end
                                return string.format(
                                        ' %s="%s"', tostring(key),
                                        util.pcdata(tostring( val