Skip to content
Snippets Groups Projects
Commit fc9a6dd0 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

py/objstr: strip: Don't strip "\0" by default.

An issue was due to incorrectly taking size of default strip characters
set.
parent 44f0a4d1
No related branches found
No related tags found
No related merge requests found
...@@ -777,7 +777,7 @@ STATIC mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) { ...@@ -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) { if (n_args == 1) {
chars_to_del = whitespace; chars_to_del = whitespace;
chars_to_del_len = sizeof(whitespace); chars_to_del_len = sizeof(whitespace) - 1;
} else { } else {
if (mp_obj_get_type(args[1]) != self_type) { if (mp_obj_get_type(args[1]) != self_type) {
bad_implicit_conversion(args[1]); bad_implicit_conversion(args[1]);
......
...@@ -32,6 +32,13 @@ print("a ".strip()) ...@@ -32,6 +32,13 @@ print("a ".strip())
print("a ".lstrip()) print("a ".lstrip())
print("a ".rstrip()) 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 # Test that stripping unstrippable string returns original object
s = "abc" s = "abc"
print(id(s.strip()) == id(s)) print(id(s.strip()) == id(s))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment