Skip to content

Commit f0469d8

Browse files
committed
string repeat of an empty string is an error
Fixes fish-shell#3898
1 parent 6fd8dc4 commit f0469d8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/builtin_string.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
10461046
wcstring storage;
10471047
bool is_empty = true;
10481048

1049-
if ((to_repeat = string_get_arg(&i, argv, &storage, streams)) != NULL) {
1049+
if ((to_repeat = string_get_arg(&i, argv, &storage, streams)) != NULL && *to_repeat) {
10501050
const wcstring word(to_repeat);
10511051
const bool rep_until = (0 < max && word.length()*count > max) || !count;
10521052
const wcstring repeated = rep_until ? wcsrepeat_until(word, max) : wcsrepeat(word, count);

tests/string.in

+9-1
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,12 @@ echo 'stdin' | string repeat -n1 'and arg'; or echo "exit 2"
132132

133133
string repeat -n; or echo "exit 2"
134134

135-
string repeat -l fakearg 2>&1 | head -n1 1>&2
135+
string repeat -l fakearg 2>&1 | head -n1 1>&2
136+
137+
string repeat ''
138+
and echo string repeat empty string did not fail
139+
140+
string repeat -n3 ''
141+
and echo string repeat empty string did not fail
142+
143+
exit 0

0 commit comments

Comments
 (0)