Commit 1550bde
committed
fix(mapper): keep all-zero arrays under omitempty (legacy behavior)
The previous fix-up rewrote the array branch to skip on fld.IsZero()
for both flags. That over-corrected: pre-omitzero, the original code's
else-if chain entered the Array|Slice arm and only set isZero on
Len()==0. Normal-length all-zero arrays ([16]byte UUIDs, [32]byte
hashes, ed25519 keys) were always emitted under omitempty.
Split the array branch so omitempty stays Len()==0 (matches legacy)
and omitzero gets the strict IsZero() rule (Go 1.24+ json semantic).
Tests:
- TestMap_OmitEmpty_AllZeroArray flipped to assert pre-PR behavior
(all-zero [16]byte kept). Was previously asserting the regression.
- TestMap_OmitZero_AllZeroArray added for the strict-zero side.
Caught by an adversarial Codex pass on pgkit#50; the earlier
self-review traced the pre-PR else-if chain incorrectly and asked
for a "fix" that wasn't actually a regression.1 parent dbc97c6 commit 1550bde
2 files changed
Lines changed: 28 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
134 | 141 | | |
135 | | - | |
| 142 | + | |
136 | 143 | | |
137 | 144 | | |
138 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
85 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
90 | | - | |
| 92 | + | |
91 | 93 | | |
92 | 94 | | |
93 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
94 | 109 | | |
95 | 110 | | |
96 | 111 | | |
| |||
0 commit comments