]> granicus.if.org Git - jq/commitdiff
Allow var bindings in path expressions (#1347)
authorNicolas Williams <nico@cryptonector.com>
Wed, 22 Feb 2017 00:11:35 +0000 (18:11 -0600)
committerNicolas Williams <nico@cryptonector.com>
Wed, 22 Feb 2017 00:11:35 +0000 (18:11 -0600)
The expression in a variable binding is not and must not be seen as
being part of a path expression in which the variable binding appears.

src/compile.c
tests/jq.test

index 44479e37ae4588767ec17e80724e0916948dec83..849e2f1d2fbb5f0047d7b4b3bcdd74503917c4db 100644 (file)
@@ -893,7 +893,7 @@ block gen_destructure(block var, block matcher, block body) {
   if (body.first && body.first->op == TOP)
     top = inst_block(block_take(&body));
 
-  return BLOCK(top, gen_op_simple(DUP), var, bind_matcher(matcher, body));
+  return BLOCK(top, gen_op_simple(DUP), gen_subexp(var), gen_op_simple(POP), bind_matcher(matcher, body));
 }
 
 // Like gen_var_binding(), but bind `break`'s wildcard unbound variable
index f510a917e593ab107aea5f0530637490bb174f65..47b842c4437ecf04f52d708106554ae7e6b7b73a 100644 (file)
@@ -1356,3 +1356,9 @@ IN(range(5;20); range(10))
 null
 true
 
+# Regression test for #1347
+(.a as $x | .b) = "b"
+{"a":null,"b":null}
+{"a":null,"b":"b"}
+
+