diff --git a/py/objstr.c b/py/objstr.c index f6214f80c9..11bfb41fc1 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -777,7 +777,7 @@ STATIC mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) { if (n_args == 1) { chars_to_del = whitespace; - chars_to_del_len = sizeof(whitespace); + chars_to_del_len = sizeof(whitespace) - 1; } else { if (mp_obj_get_type(args[1]) != self_type) { bad_implicit_conversion(args[1]); diff --git a/tests/basics/string_strip.py b/tests/basics/string_strip.py index 5d99a78e51..971a4aae53 100644 --- a/tests/basics/string_strip.py +++ b/tests/basics/string_strip.py @@ -32,6 +32,13 @@ print("a ".strip()) print("a ".lstrip()) print("a ".rstrip()) +# \0 used to give a problem + +print("\0abc\0".strip()) +print("\0abc\0".lstrip()) +print("\0abc\0".rstrip()) +print("\0abc\0".strip("\0")) + # Test that stripping unstrippable string returns original object s = "abc" print(id(s.strip()) == id(s))