Skip to content

IndexError in initials_list() when a *_list attribute contains a doubled-space element #232

Description

@derek73

first_list/middle_list/last_list are plain public attributes (not properties), so they can be assigned directly, bypassing parse_pieces's whitespace normalization. If an assigned element contains an internal double space, _process_initial (parser.py:269, initials.append(part[0])) crashes with IndexError: string index out of range, because "".split(" ") yields an empty string for the collapsed gap.

Repro:

from nameparser import HumanName
n = HumanName(first='John')
n.middle_list = ['Q  R']   # double space inside one list element
n.initials_list()          # IndexError: string index out of range

Going through the normal constructor/property paths is safe (HumanName("John Q Doe") or first="A B") since those go through parse_pieces, which normalizes whitespace. The crash only happens via direct assignment to the *_list attributes.

Found while reviewing #229 / PR #231 — unrelated to that cleanup; it's a pre-existing issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions