Commit 7fbb73c
committed
Fix leading space in surnames after capitalize() with empty middle name
capitalize() split each attribute with str.split(' '), which returns ['']
(not []) for an empty string. cap_piece() returns '' for an empty part, so an
empty middle name produced middle_list = [''], which leaked into surnames_list
(middle_list + last_list) and yielded a leading space in the surnames property:
>>> hn = HumanName('john doe'); hn.capitalize(); hn.surnames
' Doe' # leading space (should be 'Doe')
The same spurious '' element also appeared in title_list/first_list/last_list
for empty attributes. Using str.split() instead returns [] for empty strings
and is equivalent for the already-whitespace-collapsed pieces cap_piece()
returns. The suffix split (', ') is intentionally left unchanged.
Added a regression test in HumanNameCapitalizationTestCase.1 parent 1f46568 commit 7fbb73c
2 files changed
Lines changed: 26 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
984 | 984 | | |
985 | 985 | | |
986 | 986 | | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
991 | 991 | | |
992 | 992 | | |
993 | 993 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
43 | 65 | | |
44 | 66 | | |
45 | 67 | | |
| |||
0 commit comments