Repository navigation
Add type checking for variadic function arguments - #102
Open
AdamMagued wants to merge 1 commit into
Open
AdamMagued wants to merge 1 commit into
AdamMagued wants to merge 1 commit into
Conversation
In functionEntry.resolveArgs, variadic functions only validated that len(arguments) >= len(e.arguments) without performing type checking on either fixed or variadic arguments. When passing arguments of unexpected types (such as nil, strings, or numbers) to functions like merge(), downstream type assertions in handlers (e.g. jpfMerge) panicked at runtime instead of returning an evaluation error. Iterate over arguments in resolveArgs for variadic functions, checking each argument against its corresponding argSpec or the trailing variadic argSpec. Fixes jmespath#72
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add argument type validation for variadic functions in functionEntry.resolveArgs.
Problem & Root Cause
In functionEntry.resolveArgs (functions.go), non-variadic functions validate both argument count and individual argument types via argSpec.typeCheck. However, when a function entry is marked variadic: true, resolveArgs only checked len(arguments) < len(e.arguments) and bypassed argSpec.typeCheck entirely.
As a result, passing non-object values (such as nil, strings, numbers, booleans, or arrays) into functions like merge() resulted in unhandled runtime panics during downcast type assertions inside function handlers (e.g. mapped := m.(map[string]interface{}) in jpfMerge in functions.go:519), rather than cleanly returning an evaluation error.
Fix
In functionEntry.resolveArgs, iterate over all supplied arguments for variadic functions and validate each argument using argSpec.typeCheck:
If any argument fails type checking, an evaluation error is returned instead of panicking.
Verification
go-jmespath/jppanics when parameters are not JSON objects #72, and not_null() with variadic arguments.Fixes #72