]> granicus.if.org Git - jq/commitdiff
Empty arrays join/1 to an empty string, fixes #668 bug introduced by 9760245 669/head
authorJoel Purra <code+github@joelpurra.com>
Wed, 14 Jan 2015 11:24:27 +0000 (12:24 +0100)
committerJoel Purra <code+github@joelpurra.com>
Wed, 14 Jan 2015 11:27:55 +0000 (12:27 +0100)
builtin.c
tests/all.test

index 1722de7830db20d226bfa00beb230ebae7240709..d88c9d772389f2e13306361c9dc22906808580bb 100644 (file)
--- a/builtin.c
+++ b/builtin.c
@@ -1072,7 +1072,7 @@ static const char* const jq_builtins[] = {
   "def scalars: select(. == null or . == true or . == false or type == \"number\" or type == \"string\");",
   "def scalars_or_empty: select(. == null or . == true or . == false or type == \"number\" or type == \"string\" or ((type==\"array\" or type==\"object\") and length==0));",
   "def leaf_paths: paths(scalars);",
-  "def join($x): reduce .[] as $i (null; (.//\"\") + (if . == null then $i else $x + $i end));",
+  "def join($x): reduce .[] as $i (null; (.//\"\") + (if . == null then $i else $x + $i end))//\"\";",
   "def flatten: reduce .[] as $i ([]; if $i | type == \"array\" then . + ($i | flatten) else . + [$i] end);",
   "def flatten($x): reduce .[] as $i ([]; if $i | type == \"array\" and $x > 0 then . + ($i | flatten($x-1)) else . + [$i] end);",
   "def range($x): range(0;$x);",
index e0fac8dd0d4d3dd007e8733c949ec9756e8185d7..8961fed0bbe3a61f712c89cbd57b951d84344682 100644 (file)
@@ -328,8 +328,8 @@ join(",","/")
 "a/b/c/d"
 
 [.[]|join("a")]
-[[""],["",""],["","",""]]
-["","a","aa"]
+[[],[""],["",""],["","",""]]
+["","","a","aa"]
 
 # Same check for flatten/1
 flatten(-1,3,2,1)