Skip to content

Commit 9760245

Browse files
committed
join/1: respect empty strings (fix #668)
1 parent 8b5ff40 commit 9760245

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

builtin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ static const char* const jq_builtins[] = {
10651065
"def scalars: select(. == null or . == true or . == false or type == \"number\" or type == \"string\");",
10661066
"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));",
10671067
"def leaf_paths: paths(scalars);",
1068-
"def join($x): reduce .[] as $i (\"\"; . + (if . == \"\" then $i else $x + $i end));",
1068+
"def join($x): reduce .[] as $i (null; (.//\"\") + (if . == null then $i else $x + $i end));",
10691069
"def flatten: reduce .[] as $i ([]; if $i | type == \"array\" then . + ($i | flatten) else . + [$i] end);",
10701070
"def flatten($x): reduce .[] as $i ([]; if $i | type == \"array\" and $x > 0 then . + ($i | flatten($x-1)) else . + [$i] end);",
10711071
"def range($x): range(0;$x);",

tests/all.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ join(",","/")
327327
"a,b,c,d"
328328
"a/b/c/d"
329329

330+
[.[]|join("a")]
331+
[[""],["",""],["","",""]]
332+
["","a","aa"]
333+
330334
# Same check for flatten/1
331335
flatten(-1,3,2,1)
332336
[0, [1], [[2]], [[[3]]]]

0 commit comments

Comments
 (0)