Merge branch 'master' of github.com:dpgeorge/micropython
This commit is contained in:
commit
32f88410a1
11
py/objstr.c
11
py/objstr.c
|
@ -41,9 +41,20 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
|||
int len = strlen(lhs_str);
|
||||
if (start < 0) {
|
||||
start = len + start;
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
} else if (start > len) {
|
||||
start = len;
|
||||
}
|
||||
if (stop <= 0) {
|
||||
stop = len + stop;
|
||||
// CPython returns empty string in such case
|
||||
if (stop < 0) {
|
||||
stop = start;
|
||||
}
|
||||
} else if (stop > len) {
|
||||
stop = len;
|
||||
}
|
||||
return mp_obj_new_str(qstr_from_strn_copy(lhs_str + start, stop - start));
|
||||
#endif
|
||||
|
|
|
@ -22,6 +22,11 @@ print(b"123"[0:])
|
|||
print(b"123"[:0])
|
||||
print(b"123"[:-3])
|
||||
print(b"123"[:-4])
|
||||
# Range check testing, don't segfault, please ;-)
|
||||
print(b"123"[:1000000])
|
||||
print(b"123"[1000000:])
|
||||
print(b"123"[:-1000000])
|
||||
print(b"123"[-1000000:])
|
||||
# No IndexError!
|
||||
print(b""[1:1])
|
||||
print(b""[-1:-1])
|
||||
|
|
Loading…
Reference in New Issue