join/1: respect empty strings (fix #668)
This commit is contained in:
1 parent
8b5ff40402
commit
97602456e3
2 files changed
+5
-1
No files matched your search
@@ -1065,7 +1065,7 @@ static const char* const jq_builtins[] = {
|
|||||||
"def scalars: select(. == null or . == true or . == false or type == \"number\" or type == \"string\");",
|
"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 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 leaf_paths: paths(scalars);",
|
||||||
"def join($x): reduce .[] as $i (\"\"; . + (if . == \"\" 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: 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 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);",
|
"def range($x): range(0;$x);",
|
||||||
|
|||||||
@@ -327,6 +327,10 @@ join(",","/")
|
|||||||
"a,b,c,d"
|
"a,b,c,d"
|
||||||
"a/b/c/d"
|
"a/b/c/d"
|
||||||
|
|
||||||
|
[.[]|join("a")]
|
||||||
|
[[""],["",""],["","",""]]
|
||||||
|
["","a","aa"]
|
||||||
|
|
||||||
# Same check for flatten/1
|
# Same check for flatten/1
|
||||||
flatten(-1,3,2,1)
|
flatten(-1,3,2,1)
|
||||||
[0, [1], [[2]], [[[3]]]]
|
[0, [1], [[2]], [[[3]]]]
|
||||||
|
|||||||
Reference in new issue
Block a user