From b142d484d58696e7e5be33b196d131169a032a76 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Wed, 15 Mar 2017 01:07:37 -0500 Subject: [PATCH] Conditional exprs are not path exprs (fix #1368) The conditional expression in if-then-elif-else-end cannot contribute to path expressions because it doesn't change the input to any of the then/ elif/else expressions. These must be generated via gen_subexp(). See also #1366. --- src/compile.c | 2 +- tests/jq.test | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compile.c b/src/compile.c index e0bd140..8ab26af 100644 --- a/src/compile.c +++ b/src/compile.c @@ -905,7 +905,7 @@ static block gen_wildvar_binding(block var, const char* name, block body) { } block gen_cond(block cond, block iftrue, block iffalse) { - return BLOCK(gen_op_simple(DUP), cond, + return BLOCK(gen_op_simple(DUP), BLOCK(gen_subexp(cond), gen_op_simple(POP)), gen_condbranch(BLOCK(gen_op_simple(POP), iftrue), BLOCK(gen_op_simple(POP), iffalse))); } diff --git a/tests/jq.test b/tests/jq.test index 963595b..ac784ef 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -1382,4 +1382,9 @@ true {"a":null,"b":null} {"a":null,"b":"b"} +# Regression test for #1368 +(.. | select(type == "object" and has("b") and (.b | type) == "array")|.b) |= .[0] +{"a": {"b": [1, {"b": 3}]}} +{"a": {"b": 1}} + -- 2.40.0