From a76e642f4757cd43619fa071fb1203b5935d31d6 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Tue, 20 Dec 2016 11:49:58 -0800 Subject: [PATCH] hotfix(galileo) proper empty encoding as empty arr Use a workaround until https://github.com/openresty/lua-cjson/pull/16 is included in an OpenResty formal release. --- kong/plugins/galileo/alf.lua | 8 ++++++++ spec/03-plugins/05-galileo/01-alf_spec.lua | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/kong/plugins/galileo/alf.lua b/kong/plugins/galileo/alf.lua index 05060fbf2bf..4878435e690 100644 --- a/kong/plugins/galileo/alf.lua +++ b/kong/plugins/galileo/alf.lua @@ -69,6 +69,14 @@ local function hash_to_array(t) arr[#arr+1] = {name = k, value = v} end end + + -- FIXME: temporary workardound + -- remove once https://github.com/openresty/lua-cjson/pull/16 + -- is included in a formal OpenResty release. + if #arr == 0 then + return cjson.empty_array + end + return arr end diff --git a/spec/03-plugins/05-galileo/01-alf_spec.lua b/spec/03-plugins/05-galileo/01-alf_spec.lua index 2ae4c352b40..f83af511d34 100644 --- a/spec/03-plugins/05-galileo/01-alf_spec.lua +++ b/spec/03-plugins/05-galileo/01-alf_spec.lua @@ -26,6 +26,17 @@ local alf_serializer = require "kong.plugins.galileo.alf" -- input sets to the serializer. local function reload_alf_serializer() package.loaded["kong.plugins.galileo.alf"] = nil + + -- FIXME: temporary double-loading of the cjson module + -- for the encoding JSON as empty array tests in the + -- serialize() suite. + -- remove once https://github.com/openresty/lua-cjson/pull/16 + -- is included in a formal OpenResty release. + package.loaded["cjson"] = nil + package.loaded["cjson.safe"] = nil + require "cjson.safe" + require "cjson" + alf_serializer = require "kong.plugins.galileo.alf" end @@ -487,6 +498,13 @@ describe("ALF serializer", function() end) -- add_entry() describe("serialize()", function() + -- FIXME: temporary double-loading of the cjson module + -- for the encoding JSON as empty array tests in the + -- serialize() suite. + -- remove once https://github.com/openresty/lua-cjson/pull/16 + -- is included in a formal OpenResty release. + reload_alf_serializer() + local cjson = require "cjson.safe" it("returns a JSON encoded ALF object", function() local alf = alf_serializer.new()