diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index 38b0ffc35..f19706a2d 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -1046,7 +1046,7 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha wcstring storage; bool is_empty = true; - if ((to_repeat = string_get_arg(&i, argv, &storage, streams)) != NULL) { + if ((to_repeat = string_get_arg(&i, argv, &storage, streams)) != NULL && *to_repeat) { const wcstring word(to_repeat); const bool rep_until = (0 < max && word.length()*count > max) || !count; const wcstring repeated = rep_until ? wcsrepeat_until(word, max) : wcsrepeat(word, count); diff --git a/tests/string.in b/tests/string.in index ed07b9318..3ab8199db 100644 --- a/tests/string.in +++ b/tests/string.in @@ -132,4 +132,12 @@ echo 'stdin' | string repeat -n1 'and arg'; or echo "exit 2" string repeat -n; or echo "exit 2" -string repeat -l fakearg 2>&1 | head -n1 1>&2 \ No newline at end of file +string repeat -l fakearg 2>&1 | head -n1 1>&2 + +string repeat '' +and echo string repeat empty string did not fail + +string repeat -n3 '' +and echo string repeat empty string did not fail + +exit 0