google / go-jsonnet

Apache License 2.0
1.63k stars 235 forks source link

Buggy field visibility handling in`objectHas` in Go impl #736

Closed mkmik closed 5 months ago

mkmik commented 11 months ago

The Go jsonnet implementation of std.objectHas and std.objectHasEx(...,..., false) doesn't correctly honour the field visibility if an object is extended. Instead, it only checks whether the field is visible in the "current" object, even if the field is hidden in super:

How to reproduce:

std.objectHasEx({"x":: null} + {"x": null}, "x", false)

Expected value: false

Actual value: true

The C++ implementation ofstd.objectHascorrectly returnsfalse`.


Since std.get(.... inc_hidden=false) is implemented in terms of std.objectHas, that function is also buggy:

std.get(o={a:: 17} + {a: 18}, f="a", default=42, inc_hidden=false)

Expected value: 42

Actual value: 18

The C++ impl of std.get returns 42