File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 11from typing import Generator
22
33
4- def remove_unsafe_characters_from_string (string : str ) -> str :
4+ def remove_unsafe_characters_from_string (unsafe_string : str ) -> str :
55 def _remove_unsafe_characters_from_string (
6- string : str ,
6+ string_ : str ,
77 ) -> Generator [str , None , None ]:
8- string_iterator = iter (string )
8+ string_iterator = iter (string_ )
99 capitalize_next_character = False
1010
1111 # The first character must be A-z or _
@@ -27,4 +27,7 @@ def _remove_unsafe_characters_from_string(
2727 capitalize_next_character = True
2828 yield "_"
2929
30- return "" .join (_remove_unsafe_characters_from_string (string = string ))
30+ unsafe_string = unsafe_string .strip ()
31+ safe_string = "" .join (_remove_unsafe_characters_from_string (string_ = unsafe_string ))
32+ without_trailing_underscore = safe_string .rstrip ("_" )
33+ return without_trailing_underscore or "_"
Original file line number Diff line number Diff line change @@ -38,6 +38,16 @@ def test_capitalize_next_alpha_after_removed_char(self) -> None:
3838 result = remove_unsafe_characters_from_string (path )
3939 self .assertEqual (result , "my_Path_Part_2a" )
4040
41+ def test_whitespace_is_stripped (self ) -> None :
42+ description = "\t Add a new user\n \r "
43+ result = remove_unsafe_characters_from_string (description )
44+ self .assertEqual (result , "Add_A_New_User" )
45+
46+ def test_trailing_underscore_is_stripped (self ) -> None :
47+ description = "Add a new user."
48+ result = remove_unsafe_characters_from_string (description )
49+ self .assertEqual (result , "Add_A_New_User" )
50+
4151
4252if __name__ == "__main__" :
4353 unittest .main ()
You can’t perform that action at this time.
0 commit comments