Skip to content

Commit

Permalink
Fix string multiplication with a value between 0.0 and 1.0
Browse files Browse the repository at this point in the history
This commit fixes a regression of 6306ac8.
  • Loading branch information
itchyny committed Jun 12, 2020
1 parent a17dd32 commit 9334a4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ static jv f_multiply(jq_state *jq, jv input, jv a, jv b) {
num = a;
}
jv res = jv_null();
int n = jv_number_value(num);
double d = jv_number_value(num);
int n = 0.0 < d && d < 1.0 ? 1 : d;
if (n > 0) {
size_t alen = jv_string_length_bytes(jv_copy(str));
res = jv_string_empty(alen * n);
Expand Down
4 changes: 4 additions & 0 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,10 @@ indices(", ")
["a", "ab", "abc"]
["aaa", "ababab", "abcabcabc"]

[.[] * "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"]

[.[] / ","]
["a, bc, def, ghij, jklmn, a,b, c,d, e,f", "a,b,c,d, e,f,g,h"]
[["a"," bc"," def"," ghij"," jklmn"," a","b"," c","d"," e","f"],["a","b","c","d"," e","f","g","h"]]
Expand Down

0 comments on commit 9334a4a

Please sign in to comment.