Distinguish missing vs null in var resolution (use default only when missing)#58
Distinguish missing vs null in var resolution (use default only when missing)#58andras-markos wants to merge 4 commits intojamsesso:mainfrom
var resolution (use default only when missing)#58Conversation
fix: distinguish missing vs null in var resolution using MISSING
…i-config [LT-1633] update Gradle build and CircleCI config
jamsesso
left a comment
There was a problem hiding this comment.
I'm happy with the code fixes but I'm not onboard with the CI changes. Those should be a separate PR. Because the two are mixed in here, I'll have to decline.
There was a problem hiding this comment.
I'm fine upgrading Gradle, but can this be done in another PR?
There was a problem hiding this comment.
Same comment as before - bundling two different changes in a PR (missing + gradle changes) isn't ideal. I don't want to discuss two changes in a single PR. the code for MISSING seems fine and can be deployed, but this is something I'd like to think about more.
|
Sorry about that, that was not my intention. |
This fixes
varresolution so a default is applied only when the path is missing, not when the value is explicitlynull.Why
Per the JsonLogic docs, the second
varargument is a default “for values that might be missing.” Treatingnullas missing deviates from that intent and leads to surprising results.What changed
MISSINGsentinel to track “not found” during path traversal.containsKeyto differentiate an absent key from a present key withnull.MISSINGfor out-of-bounds indices.evaluate(JsonLogicVariable, …)applies the default only when the traversal yieldsMISSING; explicitnullis returned asnull.Examples
{"var": ["user.age", 42]}with{"user":{"age": null}}→ null (no default){"var": ["items.2", "missing"]}with{"items":[10,20]}→ "missing"{"var": ""}returns the entire data object (same instance)Tests
Added coverage to
VariableTests:nullreturnsnull(no default).nullor non-traversable types returnnull.varkey returns the original data object.Compatibility
Behavior change for callers who relied on “default-for-null.” This aligns with the JsonLogic spec and other interpreters.