96ed328e
json: treat null fields as absent (and Value's null as a real value)
Per the proto3 JSON spec, a null on any field means "use the field's default" — encoded as missing — with the lone exception of google.protobuf.Value, where JSON null is itself a Value carrying NullValue.NULL_VALUE. Three coupled bugs surfaced together: 1. decode_field_value used to fall through with v = box.NULL, leaving a useless box.NULL sitting in the result table for scalars. Now it returns nil for non-Value fields, PB_NULL for Value fields. 2. decode_message's repeated and map branches called `#jv` and `pairs(jv)` unconditionally; a JSON-null on either type crashed with "attempt to get length of 'void *'". Now both branches short-circuit when jv is box.NULL. 3. The nil-skip checks in the decode loop (`if dv ~= nil`) and in the codec / inline message encoders (`if v == nil then return end`) evaluated TRUE on box.NULL because Tarantool's cdata __eq aliases it to nil. Decode now uses rawequal(dv, nil); encode special-cases message kind by also accepting cdata, so the Value field's box.NULL sentinel survives all the way through to value_encode. Drops 3 entries from test/conformance/known_failures.txt (AllFieldAcceptNull, WrapperTypesWithNullValue, ValueAcceptNull). Adds 5 regression tests covering scalar / repeated / map / wrapper null treatment and the Value-NULL_VALUE exception.
Eugene Blikh <bigbes@gmail.com> — 2026-05-15 21:53:54 UTC
Commit 96ed328e533f9a6eeca34e6691fc72bf967fe124 —
view raw patch
Parent(s):
43f7b869
| File | Status | + | − |
|---|---|---|---|
cmd/protoc-gen-tarantool/internal/gen/inline.go
|
M | +6 | |
examples/expected/full/conformance/conformance_pb.lua
|
M | +1 | -1 |
examples/expected/full/hello/hello_pb.lua
|
M | +12 | -12 |
examples/expected/full/protobuf_test_messages/proto3/test_messages_proto3_pb.lua
|
M | +20 | -20 |
runtime/pb/codec.lua
|
M | +5 | -1 |
runtime/pb/json.lua
|
M | +37 | -14 |
test/conformance/known_failures.txt
|
M | -3 | |
test/conformance_test.lua
|
M | +55 |