`。[] | = empty'的令人困惑的行为

时间:2018-11-19 20:05:31

标签: jq

据我了解,在更新分配empty中使用|=会删除该条目,类似于del(path),并且del(path)也可以在数组中使用。 / p>

我试图选择性地删除和修改数组条目,但结果很奇怪。在尝试理解问题时,我将代码最小化为:

过滤器.[]|=empty
输入[0,1,2,3,4,5]
输出
[ 1, 3, 5 ]

在线试用here

显然,仅偶数数组索引也被删除。为什么?

1 个答案:

答案 0 :(得分:1)

如评论中所述,jq对 int indexName = src.lastIndexOf("/"); if (indexName == src.length()){ src = src.substring(1,indexName); } indexName = src.lastIndexOf("/"); String name = src; name = name.replace(":",""); // replace all ":" with "" name = name.replaceAll("[^a-zA-Z0-9-.]", ""); for(int i = 0; i < name.length() - 3; i++){ //replaces all but the last "." for the file extention name = name.replaceFirst(".",""); } 的处理随时间而变化。有人可能会期望,对于每个数组,A,.[] |= empty都会产生A | (.[] |= empty)的理论,即表达式应导致A中的每个项目都被[]取代。

无论如何,当前的(jq 1.6)实现显然是错误的,在此示例中尤其明显:

empty

错误报告可以提交到https://github.com/stedolan/jq/issues

相关问题