Skip to content

Commit

Permalink
chore(*): remove the default global cjson instance setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ms2008 committed Jan 9, 2024
1 parent 1601bc8 commit 9deee70
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
5 changes: 2 additions & 3 deletions kong/db/strategies/postgres/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local arrays = require "pgmoon.arrays"
local json = require "pgmoon.json"
local cjson = require "cjson"
local cjson_safe = require "cjson.safe"
local utils = require "kong.tools.utils"
local new_tab = require "table.new"
Expand Down Expand Up @@ -215,7 +214,7 @@ local function escape_literal(connector, literal, field)
elseif et == "map" or et == "record" or et == "json" then
local jsons = {}
for i, v in ipairs(literal) do
jsons[i] = cjson.encode(v)
jsons[i] = cjson_safe.encode(v)
end
return encode_array(jsons) .. '::JSONB[]'

Expand Down Expand Up @@ -526,7 +525,7 @@ local function page(self, size, token, foreign_key, foreign_entity_name, options
insert(offset, row[field_name])
end

offset = cjson.encode(offset)
offset = cjson_safe.encode(offset)
offset = encode_base64(offset, true)

return rows, nil, offset
Expand Down
3 changes: 1 addition & 2 deletions kong/db/strategies/postgres/tags.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local cjson = require "cjson"
local cjson_safe = require "cjson.safe"


Expand Down Expand Up @@ -118,7 +117,7 @@ local function page(self, size, token, options, tag)
last_ordinality
}

offset = cjson.encode(offset)
offset = cjson_safe.encode(offset)
offset = encode_base64(offset, true)

return rows, nil, offset
Expand Down
5 changes: 1 addition & 4 deletions kong/globalpatches.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ return function(options)
local meta = require "kong.meta"


local cjson = require("cjson")
local cjson_safe = require("cjson.safe")
cjson.encode_sparse_array(nil, nil, 2^15)
cjson.encode_number_precision(constants.CJSON_MAX_PRECISION)
cjson_safe.encode_sparse_array(nil, nil, 2^15)
cjson_safe.encode_number_precision(constants.CJSON_MAX_PRECISION)

Expand All @@ -29,7 +26,7 @@ return function(options)
-- let pb decode arrays to table cjson.empty_array_mt metatable
-- so empty arrays are encoded as `[]` instead of `nil` or `{}` by cjson.
pb.option("decode_default_array")
pb.defaults("*array", cjson.empty_array_mt)
pb.defaults("*array", cjson_safe.empty_array_mt)

if options.cli then
-- disable the _G write guard alert log introduced in OpenResty 1.15.8.1
Expand Down

0 comments on commit 9deee70

Please sign in to comment.