diff options
author | Damien George <damien.p.george@gmail.com> | 2017-06-02 13:07:22 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-06-02 13:07:22 +1000 |
commit | 9f85c4fe488a8f123348786448f534263dc003e1 (patch) | |
tree | 7c7bb79b6f13946fb2af4e6e9209402dae8c5c7f | |
parent | ab954ed5136af8be910b3c3fb9246bad6289a3a4 (diff) | |
download | micropython-9f85c4fe488a8f123348786448f534263dc003e1.tar.gz micropython-9f85c4fe488a8f123348786448f534263dc003e1.zip |
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.
-rw-r--r-- | py/objstr.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c index a1e2235720..1d2a280453 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -602,6 +602,11 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { GET_STR_DATA_LEN(args[0], s, len); mp_int_t splits = mp_obj_get_int(args[2]); + if (splits < 0) { + // Negative limit means no limit, so delegate to split(). + return mp_obj_str_split(n_args, args); + } + mp_int_t org_splits = splits; // Preallocate list to the max expected # of elements, as we // will fill it from the end. |