-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(pdk.log): fix a bug that pdk.log.serialize() does not properly handle JSON nulls #13376
Conversation
when json entity set via pdk.log.set_serialize_value contains cjson.null as value. FTI-6096
b56d3d3
to
8ea095b
Compare
Co-authored-by: Zachary Hu <6426329+outsinre@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both cjson.null
and ngx.null
are userdata. Since the PR is treating cjson.null
as a valid value, do you think the last one ngx.null
should also be considered?
it("does not fail when coming across 'cjson.null' in response body", function() | ||
local cjson_null = require "cjson".null | ||
kong.log.set_serialize_value("response.body", cjson_null) | ||
local pok, value = pcall(kong.log.serialize, {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why it need be wrap by a pcall
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just have a change to handle exception thrown from the serialize()
|
kong/pdk/log.lua
Outdated
@@ -640,7 +641,7 @@ do | |||
|
|||
local function is_valid_value(v, visited) | |||
local t = type(v) | |||
if v == nil or t == "number" or t == "string" or t == "boolean" then | |||
if v == nil or v == cjson_null or t == "number" or t == "string" or t == "boolean" then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a blocker for this PR, but we should also exclude FFI null from it
local ffi = require "ffi"
local n = ffi.new("void*")
print(tostring(n))
print(n == nil)
local cjson = require "cjson"
print(cjson.encode(n))
outputs
cdata<void *>: NULL
true
ERROR: /tmp/a.lua:9: Cannot serialise cdata: type not supported
Successfully created cherry-pick PR for |
Summary
As titled, this PR is to fix the bug reported by FTI-6096
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Fix #FTI-6096