Skip to content

Commit 2c91cf5

Browse files
committed
ported compatibility tests for 1.5.4 to begin exploring actual compatibility
1 parent 31e6058 commit 2c91cf5

File tree

1,124 files changed

+14742
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,124 files changed

+14742
-9
lines changed

callable.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ func (c *goCallable) validateArgCount(argv []reflect.Value) ([]reflect.Value, er
246246

247247
argc := len(argv)
248248

249+
// Check for undefined arguments first
250+
// This ensures that $base64encode() with no arguments returns undefined
251+
// rather than trying to use the context as an argument
252+
if c.undefinedHandler != nil && c.undefinedHandler(argv) {
253+
// TODO: Validate the other arguments before doing
254+
// this. Otherwise we mask errors with the other
255+
// arguments.
256+
return nil, jtypes.ErrUndefined
257+
}
258+
259+
// Only use context handler if we haven't determined the result is undefined
249260
if c.contextHandler != nil && c.contextHandler(argv) {
250261
// TODO: Return an error if the evaluation context
251262
// is not the correct type.
@@ -254,13 +265,6 @@ func (c *goCallable) validateArgCount(argv []reflect.Value) ([]reflect.Value, er
254265
argv = append(newargv, argv...)
255266
}
256267

257-
if c.undefinedHandler != nil && c.undefinedHandler(argv) {
258-
// TODO: Validate the other arguments before doing
259-
// this. Otherwise we mask errors with the other
260-
// arguments.
261-
return nil, jtypes.ErrUndefined
262-
}
263-
264268
paramCount := len(c.params)
265269

266270
for i := len(argv); i < paramCount; i++ {

env.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ var baseEnv = initBaseEnv(map[string]Extension{
156156
},
157157
"base64decode": {
158158
Func: jlib.Base64Decode,
159-
UndefinedHandler: defaultUndefinedHandler,
160-
EvalContextHandler: defaultContextHandler,
159+
UndefinedHandler: jtypes.ArgCountEquals(0),
160+
EvalContextHandler: nil,
161161
},
162162
"decodeUrl": {
163163
Func: jlib.DecodeURL,

eval.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,14 @@ func evalBlock(node *jparse.BlockNode, data reflect.Value, env *environment) (re
528528
// environment of the correct size?
529529
env = newEnvironment(env, 0)
530530

531+
// If the block is empty, return an explicit nil value, not undefined.
532+
// Empty blocks should return null/nil according to JSONata spec.
533+
if len(node.Exprs) == 0 {
534+
// Return a nil value wrapped in a reflect.Value.
535+
// This will be interpreted as null in JSON or undefined in JSONata context.
536+
return reflect.Zero(jtypes.TypeInterface), nil
537+
}
538+
531539
// Evaluate all expressions in the block.
532540
for _, node := range node.Exprs {
533541
res, err = eval(node, data, env)

0 commit comments

Comments
 (0)