diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-08-29 00:06:21 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-08-29 00:06:21 +0300 |
commit | 37379a2974190ab0fc97f840112d5a40c907368b (patch) | |
tree | 7c4d0ce9e82aa58ca8af5198a57f1e3211fb7a82 /py/objstr.c | |
parent | c5c095690fc8294068e88c71baca92bf757ad91c (diff) |
py/objstr: startswith, endswith: Check arg to be a string.
Otherwise, it will silently get incorrect result on other values types,
including CPython tuple form like "foo.png".endswith(("png", "jpg"))
(which MicroPython doesn't support for unbloatedness).
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/py/objstr.c b/py/objstr.c index d4c038a68..f04bd90be 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -726,7 +726,8 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rindex_obj, 2, 4, str_rindex); STATIC mp_obj_t str_startswith(size_t n_args, const mp_obj_t *args) { const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); GET_STR_DATA_LEN(args[0], str, str_len); - GET_STR_DATA_LEN(args[1], prefix, prefix_len); + size_t prefix_len; + const char *prefix = mp_obj_str_get_data(args[1], &prefix_len); const byte *start = str; if (n_args > 2) { start = str_index_to_ptr(self_type, str, str_len, args[2], true); @@ -740,7 +741,8 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_startswith_obj, 2, 3, str_startswith); STATIC mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) { GET_STR_DATA_LEN(args[0], str, str_len); - GET_STR_DATA_LEN(args[1], suffix, suffix_len); + size_t suffix_len; + const char *suffix = mp_obj_str_get_data(args[1], &suffix_len); if (n_args > 2) { mp_raise_NotImplementedError("start/end indices"); } |