Fix string multiplication by 0 (and less than 1) to emit empty string

This commit is contained in:
itchyny authored and Nico Williams committed 2023-07-08 22:25:22 -05:00
1 parent 88b45771bd
commit cac3ea3726
2 files changed
+10 -4

No files matched your search

+5 -3
View File
@@ -359,10 +359,12 @@ static jv f_multiply(jq_state *jq, jv input, jv a, jv b) {
str = b;
num = a;
}
jv res = jv_null();
jv res;
double d = jv_number_value(num);
int n = 0.0 < d && d < 1.0 ? 1 : d;
if (n > 0) {
if (d < 0 || isnan(d)) {
res = jv_null();
} else {
int n = d;
size_t alen = jv_string_length_bytes(jv_copy(str));
res = jv_string_empty(alen * n);
for (; n > 0; n--) {
+5 -1
View File
@@ -1286,7 +1286,11 @@ indices(", ")
[.[] * "abc"]
[-1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 3.7, 10.0]
[null,null,null,"abc","abc","abc","abcabcabc","abcabcabcabcabcabcabcabcabcabc"]
[null,null,"","","abc","abc","abcabcabc","abcabcabcabcabcabcabcabcabcabc"]
[. * (nan,-nan)]
"abc"
[null,null]
[.[] / ","]
["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]