Skip to content

Commit 9f85c4f

Browse files
committed
py/objstr: Catch case of negative "maxsplit" arg to str.rsplit().
Negative values mean no limit on the number of splits so should delegate to the .split() method.
1 parent ab954ed commit 9f85c4f

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

py/objstr.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,11 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) {
602602
GET_STR_DATA_LEN(args[0], s, len);
603603

604604
mp_int_t splits = mp_obj_get_int(args[2]);
605+
if (splits < 0) {
606+
// Negative limit means no limit, so delegate to split().
607+
return mp_obj_str_split(n_args, args);
608+
}
609+
605610
mp_int_t org_splits = splits;
606611
// Preallocate list to the max expected # of elements, as we
607612
// will fill it from the end.

0 commit comments

Comments
 (0)