Skip to content

Commit

Permalink
Eval eval/1 args with correct env
Browse files Browse the repository at this point in the history
Fixes issue with: "1+2" as $e | eval($e) -> 3
  • Loading branch information
wader committed Jan 2, 2025
1 parent b498f45 commit 8a40917
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jqjq.jq
Original file line number Diff line number Diff line change
Expand Up @@ -2596,7 +2596,7 @@ def builtin_undefined_func($globals; $builtins_env):
| eval_ast(
$f.args[0];
[];
$builtins_env;
$f.env;
builtin_undefined_func($globals; $builtins_env)
) as [$_path, $expr]
| $f.input
Expand Down
15 changes: 15 additions & 0 deletions jqjq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1257,3 +1257,18 @@ null
try eval(". as {$a $b} | .") catch "failed"
null
"failed"

# eval expr arg as normal
"1+2" as $a | eval($a)
null
3

# also nested
"\"1+2\" as $b | eval($b)" as $a | eval($a)
null
3

# and env don't leak into eval (maybe should be an option?)
try 3 as $e | eval("$e") catch .
null
"undefined function $e"

0 comments on commit 8a40917

Please sign in to comment.