Skip to content

Commit 1da7341

Browse files
committed
Fix jq-template to properly count {{ }} pairs
This fixes edge cases like: ``` {{ foo }} {{ bar }} {{ baz | buzz }} ```
1 parent faf7efe commit 1da7341

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

scripts/jq-template.awk

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ function jq_escape(str, # parameters
1717
return out
1818
}
1919

20+
# return the number of times needle appears in haystack
21+
function num(haystack, needle, # parameters
22+
ret, i ) # locals
23+
{
24+
ret = 0
25+
while (i = index(haystack, needle)) {
26+
ret++
27+
haystack = substr(haystack, i + length(needle))
28+
}
29+
return ret
30+
}
31+
2032
BEGIN {
2133
jq_expr_defs = ""
2234
jq_expr = ""
@@ -76,7 +88,7 @@ function append_jq(expr) {
7688
agg_jq = agg_jq line
7789
line = ""
7890

79-
if (!index(agg_jq, CLOSE)) {
91+
if (num(agg_jq, OPEN) > num(agg_jq, CLOSE)) {
8092
next
8193
}
8294

0 commit comments

Comments
 (0)