Skip to content

Commit

Permalink
Merge pull request #669 from joelpurra/join-empty-array-668
Browse files Browse the repository at this point in the history
Empty arrays join/1 to an empty string, fixes #668 bug introduced by 9760245
  • Loading branch information
nicowilliams committed Jan 14, 2015
2 parents aeb52e2 + 4d05dc5 commit cca3e92
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion builtin.c
Expand Up @@ -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);",
Expand Down
4 changes: 2 additions & 2 deletions tests/all.test
Expand Up @@ -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)
Expand Down

0 comments on commit cca3e92

Please sign in to comment.