adobe / json-formula

Query language for JSON documents
http://opensource.adobe.com/json-formula/
Apache License 2.0
19 stars 8 forks source link

Calling registered functions with 0 arguments. #178

Open Eswcvlad opened 1 month ago

Eswcvlad commented 1 month ago

Currently in the spec:

The registered function may take one parameter.

It is pretty clear, that it would be implemented by just evaluating the expression with the argument as the contextual input JSON. But it is not quite clear, what that input should be in the json-formula context, when 0 arguments are provided.

In the current implementation, it looks like it just has js "undefined" as the input, which can leak in the results. For example, an expression like register("_identity", &@) || _identity() results in undefined.

Maybe it would be better to specify the default value for the argument in such cases, like null or {}?

JohnBrinkman commented 1 month ago

Good question. I think null makes most sense.