Skip to content

Commit ab20d00

Browse files
committed
Added some guards against bad data in name_parts().
- Legacy-Id: 11285
1 parent 9e382bb commit ab20d00

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

ietf/person/name.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
def name_parts(name):
44
prefix, first, middle, last, suffix = "", "", "", "", ""
55

6-
# if we got a name on the form "Hello There (Foo Bar)", get rid of
6+
if not name.strip():
7+
return prefix, first, middle, last, suffix
8+
9+
# if we got a name on the form "Some Name (Foo Bar)", get rid of
710
# the paranthesized part
811
name_with_paren_match = re.search("^([^(]+)\s*\(.*\)$", name)
912
if name_with_paren_match:
@@ -13,7 +16,7 @@ def name_parts(name):
1316
if len(parts) > 2 and parts[0] in ["M", "M.", "Sri", ] and "." not in parts[1]:
1417
prefix = parts[0];
1518
parts = parts[1:]
16-
if parts[0] in ["Mr", "Mr.", "Mrs", "Mrs.", "Ms", "Ms.", "Miss", "Dr", "Dr.", "Doctor", "Prof", "Prof.", "Professor", "Sir", "Lady", "Dame", ]:
19+
if len(parts) > 1 and parts[0] in ["Mr", "Mr.", "Mrs", "Mrs.", "Ms", "Ms.", "Miss", "Dr", "Dr.", "Doctor", "Prof", "Prof.", "Professor", "Sir", "Lady", "Dame", ]:
1720
prefix = parts[0];
1821
parts = parts[1:]
1922
if len(parts) > 2:

0 commit comments

Comments
 (0)